Wednesday, January 18, 2012

Cut or remove comments from a file with grep on linux

I needed to remove the comments and blank lines to cleanup a config file (namely, the squid.conf file which had a thousand comments).

grep -ve '^#' -ve '^$' squid.conf

The -v flag negates the search and the -e flag uses a regex to do the search. I just happened to have used just two regexes on this particular line, but feel free to use as many as you need on your file.

I found this line to be very useful as I'm working with config files all day and sometimes, mostly when I actually know what I'm doing and don't need any references, I want those config files to be cleaned up to be easier on the eyes ;-)

Carlos

No comments:

Followers

About me

Santa Fe, Argentina
Programador Web, PHP, MySQL, JQuery, Administrador Linux. LAMP, Lighttpd, Nginx.