You are not logged in.

#1 2010-01-12 15:21:49

perbh
Member
From: Republic of Texas
Registered: 2005-03-04
Posts: 765

removing comments from .conf files

Far too often - when checking out a .conf-file, there is a pletoria of comments and empty lines - in most cases, comments start with a '#'.
This li'l alias will remove all the verbosity:

alias stripcom='egrep -v "^[ \t]*#|^[ \t]*$"'

example of use:

stripcom /etc/vsftpd.conf

enjoy!

[edit]
had to allow for spaces/tabs _before_ the '#' ...
[/edit]
[more_edit]
guess I should do the same for end-of-line as well ... :-(
[/edit]

Last edited by perbh (2010-01-12 15:43:42)

Offline

#2 2010-01-12 16:28:02

eldragon
Member
From: Buenos Aires
Registered: 2008-11-18
Posts: 1,029

Re: removing comments from .conf files

................................ why?

Offline

#3 2010-01-12 17:05:14

perbh
Member
From: Republic of Texas
Registered: 2005-03-04
Posts: 765

Re: removing comments from .conf files

*sigh* because - when people are asked to show their conf-files - you have to scroll down ad-infinitum to get to the juicy bits , those that really count. And all-to-often you look at the entries and miss out on the leading '#' - that's why! Using the above will give you only the 'valied' entries. But hey - you are free to ignore it!

Offline

#4 2010-01-12 17:54:56

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,799
Website

Re: removing comments from .conf files

i use it to see how many lines of code it took me to accomplish a given task.

egrep -v "^\s*(#|$)" /something.sh | wc -l

Offline

#5 2010-01-12 18:30:13

perbh
Member
From: Republic of Texas
Registered: 2005-03-04
Posts: 765

Re: removing comments from .conf files

brisbin33 wrote:

i use it to see how many lines of code it took me to accomplish a given task.

egrep -v "^\s*(#|$)" /something.sh | wc -l

eeeek! that's even better!

Offline

#6 2010-01-12 21:02:27

arch0r
Member
From: From the Chron-o-John
Registered: 2008-05-13
Posts: 597

Re: removing comments from .conf files

sed -i "/^#/d;/^ *$/d"

also works

Offline

#7 2010-01-12 21:26:55

apollokk
Member
From: Please delete me!
Registered: 2009-03-23
Posts: 157
Website

Re: removing comments from .conf files

facepalm.jpg

OK, it's a good idea, but there's no point on doing that.


/me wants you to detele this account... please delete it.

Offline

#8 2010-01-12 21:36:27

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: removing comments from .conf files

apollokk wrote:

http://scienceblogs.com/insolence/facepalm.jpg

OK, it's a good idea, but there's no point on doing that.

You might want to read the entire thread - specifically, this bit:

perbh wrote:

*sigh* because - when people are asked to show their conf-files - you have to scroll down ad-infinitum to get to the juicy bits , those that really count. And all-to-often you look at the entries and miss out on the leading '#' - that's why! Using the above will give you only the 'valied' entries. But hey - you are free to ignore it!

The point is to cut down the amount of clutter in posts. It's an excellent idea.


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#9 2010-01-12 21:41:19

jac
Member
From: /home/jac
Registered: 2009-05-19
Posts: 431
Website

Re: removing comments from .conf files

arch0r wrote:

sed -i "/^#/d;/^ *$/d"

Accomplishes something different, right? That actually removes them from the file, in place?

Offline

#10 2010-01-12 21:57:59

EnvoyRising
Member
Registered: 2008-08-08
Posts: 118

Re: removing comments from .conf files

If you have xclip installed, couldn't you use:

egrep -v "^\s*(#|$)" /something.sh | xclip -selection c

to copy the contents of a config file, script, etc without comments directly to the clipboard, ready to be pasted into the forums?

Offline

Board footer

Powered by FluxBB