GREP
Hi Linux Gurus
Could someone tell me how I can grep all uncommented lines in a file on linux? Thank you in advance. |
What have you done so far?
You should look at the "-v" option of grep, and the "^" regex pattern. |
I have used 'egrep -v '^#' file.conf' but the problem is that it has so many blank lines/spaces. Any suggstion?
|
So, what is your problem?
What are you REALLY trying to do? Are you saying that you want to remove blank lines as well? Code:
grep -v ^# filename | sed '/^$/d' |
This will exclude comment lines with leading spaces, TABs and so on (if any) and empty lines with spaces (if any). It will preserve lines of code with trailing comments:
Code:
grep -E -v '^[[:space:]]*#|^[[:space:]]*$' file |
All times are GMT -5. The time now is 12:02 PM. |