[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Striping comment from configuration files on stdout



Raj Kiran Grandhi wrote:
Jean-Louis Crouzet wrote:
Jochen Schulz wrote:
Jean-Louis Crouzet:
#cat sip.conf | grep -v "^;"

That's a useless use of cat. :) You may instead just do

grep -v '^;' sip.conf

If you want to strip empty lines and lines beginning with whitespace
followed by a ';' as well, do

grep -E -v '(^\s*;)|^\s*$'

J.
OK thanks for the tip now running. I still need display line such as

bindport=5060 ; UDP Port to bind to (SIP standard port is 5060)

but not line such as
; Set this to your host name or domain name

Try this:
grep -v '^\s*;\|^\s*$'|sed -e 's/;.*$//'

The grep eliminates commented lines and blank lines. sed then strips away the comment from the remaining lines. You can even sed first and grep later like:

sed -e 's/;.*$//'|grep -v '^\s*$'

You can even eliminate grep altogether with

sed -e 's/;.*$//;/^\s*$/ d'


Raj,

looks like the sed only gave me by far the best results, many thanks for this.
Have a nice day.

Regards,
JL



Reply to: