0

This is my txt file.

apache2                     install
apache2-bin                 install
apache2-data                    install
apache2-utils                   install
libapache2-mod-php5.6               install
libapache2-mod-php5.6               install
php-common                  install
php5.6                      install
php5.6-cli                  install
php5.6-common                   install
php5.6-json                 install
php5.6-opcache                  install
php5.6-readline                 install
libmysqlclient20:i386               install
libmysqlcppconn7v5              install
mysql-client                    install
mysql-client-5.7                install
mysql-client-core-5.7               install
mysql-common                    install
mysql-server                    install
mysql-server-5.7                install
mysql-server-core-5.7               install
mysql-utilities                 install
mysql-workbench                 install
mysql-workbench-data                install
python-mysql.connector              install

I want remove these words called install and the spaces between the module, after I want transform the result to a code inline to me use, like some these:

$ sudo apt-get remove apache2 apache2-bin apache-data....

I can make this in a text editor, but I can need to know how to make this to future whitout use a text editor.

Resuming: From my txt file, I want something like this:

apache2 apache2-bin apache2-data apache2-utils libapache2-mod-php5.0 ...

2 Answers 2

0

To answer your original question on how to remove lines of text from a textfile:

grep -v pattern lists.txt > new_lists.txt
2
  • See the edition, do you can help me?
    – Marcelo
    May 12, 2017 at 22:52
  • I don't know what you mean. Your question doesn't make sense to me.
    – mtak
    May 12, 2017 at 22:55
0

You must use two tools: sed and tr

sed -e 's/\s*install\s*$//g' txt|tr '\n' ' '

sed removes everything except packages names. tr replaces new lines with space.

sudo apt-get remove `sed -e 's/\s*install\s*$//g' txt|tr '\n' ' '`

Another solution: awk and tr

awk -e '{print $1}' < txt|tr '\n' ' '

awk prints first column from input data.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .