Only showing uncommented lines of a file?


Recommended Posts

How can I only see the uncommented lines of a .conf file? I remember someone answering this question in a thread to me some time in the past, but I can't find it and I've exhausted the search capabilities of this forum. Kind of like the opposite of grep, or grep matching commented lines but showing me the inverse.

Thanks!

-nic

if reading from stdin:

sed -e "s@#.*@@g"

to read from file.conf and print to stdout:

sed -e "s@#.*@@g" file.conf

to read from file.conf and write to file.conf

sed -i -e "s@#.*@@g" file.conf

That's if you're using # for comment, replace it with whatever comment style you use.

sed -e "s@#.*@@g" smb.conf | sed -e "s@;.*@@g"

worked for removing comments from my smb.conf file (which uses both "#" and ";" for comments )

is there anyway to combine these oh wise regular expression master? Also, how do I get rid of the white space?

thanks a million!

-nic

I was able to get similar results using grep (and understanding a bit more of what i was doing)

grep --regexp="#" -v smb.conf | grep --regexp=";" -v | grep .

I'm still unclear how to combine all of this.. there has to be some sort of an OR operator on the input.

-v option inverses the output (like i was looking for).

grep .

removes all the white space.

Also, my found method will remove lines with a # or ; in them, not only if it is the first character.

I need to find out what:

"s@#.*@@g"

means in regular expressions.

I can't seem to get my mind around those, and they seem to be very useful to those who are in the know.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.