How to cat a file removing commented lines in Unix/Linux How to cat a file removing commented lines in Unix/Linux, cat file, remove commented lines
How to cat a file removing commented lines in Unix/Linux
Many configuration files meight have lots of commented lines that wouldn't be usefull in some situations. Here's how to remove commented lines from a file:
$ cat some.file #Commented line 1 Uncommented line 1 #commented line 2 Uncommented line 2 #Commented line 3 Uncommented line 3
The file some.file has 3 commented lines and 3 uncommented lines. (In this example # is the character that comments the line) and there is at least one command to remove commented lines.
1.
$ cat some.file | grep -v ^# Uncommented line 1 Uncommented line 2 Uncommented line 3
2.
$ grep -v ^# some.file Uncommented line 1 Uncommented line 2 Uncommented line 3
-v argument fro grep means
-v, --invert-match Invert the sense of matching, to select non-matching lines.
^# - means to match ( inverse match, -v ) the lines that start with the escaped () character #.
Note: Other configuration files meight have commented lines starting with ; , like php.ini configuration for php. Use google/yahoo to search for grep and regular expressions to have a larger idea.
Designed and developed by Andrei Manescu. Optimized for Mozilla Firefox.
Copyright 2007 Andrei Manescu
All trademarks and copyrights on this page are owned by their respective owners. Comments are owned by those who posted them.