I have a text file with lots of package names.
package1
package2
# comment
# installing package3 because it was needed for...
package 3
package 4
How can I mass install all packages inside the text file without removing the comments?
I have a text file with lots of package names.
package1
package2
# comment
# installing package3 because it was needed for...
package 3
package 4
How can I mass install all packages inside the text file without removing the comments?
Something along these lines ought to do the trick.
The $(something) construction runs the something command, inserting its output in the command line.
The grep command will exclude any line beginning with a #, optionally allowing for whitespace before it. Then the tr command replaces newlines with spaces.
The following command is a (slight) improvement over the alternative because
sudo apt-get install
is not executed when the package list is empty.Note that the
-a
option reads items directly from a file instead of standard input. We don't want to pipe a file intoxargs
because stdin must remain unchanged for use byapt-get
.Given a package list file
package.list
, try:I use this simple solution:
grep
finds all lines that don't start with a#
and gives them as arguments tosudo apt install
.Inspired by the accepted answer here and this answer on removing comments:
Well, here's my solution to install a list of packages I have for fresh install:
In a
bash
function :grep
explanation :-o
keep only the part of line that matches the expression^[^#]
anything that does not start with a#
[[:alnum]-]*
a sequence of letters, numbers and-