How can I "cat" a file and remove commented lines?
You can use:
sed -e '/^;/d' php.ini
You don't need to pipe a file thru grep, grep takes filename(s) as command line args.
grep -v '^#' file1 file2 file3
will print all lines EXCEPT those that begin with a # char. you can change the comment char to whatever you wish.
If you have more than one comment char (assuming its at the beginning of a line)
egrep -v '^(;|#|//)' filelist
egrep
can save you the use of cat
. In other words, create less processes (egrep
vs cat
+egrep
) and use less buffers (pipe from cat
to egrep
vs no pipe).
It is generally a good idea to limit the use of cat
if you simply want to pass a file to a command that can read it on its own.
With this said, the following command will remove comments, even if they are indented with spaces or tabs:
egrep -v '^[[:blank:]]*;' file.ini