Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
TIP Strip comments when posting config files
View unanswered posts
View posts from last 24 hours

Goto page Previous  1, 2  
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
jmbsvicetto
Moderator
Moderator


Joined: 27 Apr 2005
Posts: 4734
Location: Angra do Heroísmo (PT)

PostPosted: Tue Feb 14, 2006 7:40 pm    Post subject: Reply with quote

Congratulations. Those are all very good scripts to strip comments.
All we need now is that users read this thread before posting their config files and remember to use the [ code ] and [ /code ] tags.
_________________
Jorge.

Your twisted, but hopefully friendly daemon.
AMD64 / x86 / Sparc Gentoo
Help answer || emwrap.sh
Back to top
View user's profile Send private message
Joe User
n00b
n00b


Joined: 21 Mar 2004
Posts: 10
Location: Germany

PostPosted: Sun May 07, 2006 10:35 am    Post subject: Reply with quote

This version strips out comment and blank lines:

Code:
sed '/^[[:space:]]*\([#;].*\)*$/d'

_________________
PayPal.Me/JoeUserFreeBSD Remote Installation
Back to top
View user's profile Send private message
al
Guru
Guru


Joined: 26 Dec 2002
Posts: 304
Location: Scotland

PostPosted: Thu Jun 15, 2006 11:40 am    Post subject: Reply with quote

x1jmp wrote:
Thanks for this tip with sed!

My version is this, which also deletes lines with ";", like the smb.conf
Code:
sed -e 's/[#;].*//;/^\s*$/d'

It's also possible to add exactly this into the .bashrc as an alias.


Thanks brilliant!

I've been looking for something to strip the ";" comments out of my Asterisk files while i'm still setting it up.

Thanks.

:D :D :D
Back to top
View user's profile Send private message
chrismortimore
l33t
l33t


Joined: 03 Dec 2005
Posts: 721
Location: Edinburgh, UK

PostPosted: Wed Aug 09, 2006 6:13 pm    Post subject: Reply with quote

All these look very complex...
Code:
grep -e "^[^#]"
works for me, and you can replace the "#" for something else if you need to. Althought it doesn't take account of whitespace, but I find 9 times out of 10 it's enough.
_________________
Desktop: AMD Athlon64 3800+ Venice Core, 2GB PC3200, 2x160GB 7200rpm Maxtor DiamondMax 10, 2x320GB WD 7200rpm Caviar RE, Nvidia 6600GT 256MB
Laptop: Intel Pentium M, 512MB PC2700, 60GB 5400rpm IBM TravelStar, Nvidia 5200Go 64MB
Back to top
View user's profile Send private message
tomk
Bodhisattva
Bodhisattva


Joined: 23 Sep 2003
Posts: 7221
Location: Sat in front of my computer

PostPosted: Sat Nov 25, 2006 12:10 am    Post subject: Reply with quote

Just updated it (only two and a half years late :)) so that it takes into account whitespace before a comment, lines that only contain whitespace and so that it uses just one grep process.
_________________
Search | Read | Answer | Report | Strip
Back to top
View user's profile Send private message
bunkacid
Tux's lil' helper
Tux's lil' helper


Joined: 11 Jan 2005
Posts: 111
Location: Laguna Hills, CA

PostPosted: Tue Dec 19, 2006 1:25 pm    Post subject: Reply with quote

thanks, i only just found this useful "one liner" to include in my ~/bin
Back to top
View user's profile Send private message
hielvc
Advocate
Advocate


Joined: 19 Apr 2002
Posts: 2805
Location: Oceanside, Ca

PostPosted: Sat Jan 13, 2007 5:40 pm    Post subject: Reply with quote

Shortest
Code:
 sed '/^#\|^$/d' /etc/make.conf.example

_________________
An A-Z Index of the Linux BASH command line
Back to top
View user's profile Send private message
nanafunk
n00b
n00b


Joined: 29 Jun 2005
Posts: 36

PostPosted: Mon Jan 15, 2007 12:48 am    Post subject: Reply with quote

Code:
[%] cat a
#comment1
 #comment2
[%] sed '/^#\|^$/d' a
 #comment2
Back to top
View user's profile Send private message
hielvc
Advocate
Advocate


Joined: 19 Apr 2002
Posts: 2805
Location: Oceanside, Ca

PostPosted: Tue Jan 16, 2007 12:22 am    Post subject: Reply with quote

Ratsafrats :!: I went back re-read the submissions, and for sed Eds " sed 's/#.*//;/^\s*$/d' "$@" " and x1jmp's sed 's/[#;].*//;/^\s*$/d' it is obvious that they new the great secret of the shortest sed for SIMPLE :P configs but hide it in supurfluous hyperbole and you fell for it :lol:

EDIT In a kind hearted effort, I remove the dangling "-e" form pooor old Eds and x1jmps ostentatious seds. :wink:
_________________
An A-Z Index of the Linux BASH command line
Back to top
View user's profile Send private message
thomasvk
Guru
Guru


Joined: 19 Mar 2005
Posts: 597

PostPosted: Sat Jan 27, 2007 1:03 pm    Post subject: Reply with quote

A lot of diffent ones,... but which one is the best? :P :roll:
Back to top
View user's profile Send private message
Sakkath
Apprentice
Apprentice


Joined: 06 Nov 2005
Posts: 198
Location: Pawtucket, RI

PostPosted: Fri Feb 09, 2007 1:53 pm    Post subject: Reply with quote

Maybe `confcat` should go in baselayout 8O
_________________
The person who makes no mistakes does not usually make anything.

Please add [SOLVED] to the subject of your original post when you feel that your problem is resolved.
Back to top
View user's profile Send private message
timeBandit
Bodhisattva
Bodhisattva


Joined: 31 Dec 2004
Posts: 2719
Location: here, there or in transit

PostPosted: Sat Feb 10, 2007 5:56 pm    Post subject: Reply with quote

Sakkath wrote:
Maybe `confcat` should go in baselayout 8O

Or perhaps gentoolkit. I named mine ecat for Gentoo-ishness and as a nod to Ed Catmur. :)
_________________
Plants are pithy, brooks tend to babble--I'm content to lie between them.
Super-short f.g.o checklist: Search first, strip comments, mark solved, help others.
Back to top
View user's profile Send private message
Sakkath
Apprentice
Apprentice


Joined: 06 Nov 2005
Posts: 198
Location: Pawtucket, RI

PostPosted: Sat Feb 10, 2007 6:15 pm    Post subject: Reply with quote

timeBandit wrote:
Sakkath wrote:
Maybe `confcat` should go in baselayout 8O

Or perhaps gentoolkit. I named mine ecat for Gentoo-ishness and as a nod to Ed Catmur. :)

Yeah that's a better idea :P.
_________________
The person who makes no mistakes does not usually make anything.

Please add [SOLVED] to the subject of your original post when you feel that your problem is resolved.
Back to top
View user's profile Send private message
carpman
Advocate
Advocate


Joined: 20 Jun 2002
Posts: 2202
Location: London - UK

PostPosted: Mon Jun 11, 2007 10:28 am    Post subject: Reply with quote

cheers very helpful
_________________
Work Station - 64bit
Gigabyte GA X48-DQ6 Core2duo E8400
8GB GSkill DDR2-1066
SATA Areca 1210 Raid
BFG OC2 8800 GTS 640mb
--------------------------------
Notebook
Samsung Q45 7100 4gb
Back to top
View user's profile Send private message
VinzC
Watchman
Watchman


Joined: 17 Apr 2004
Posts: 5098
Location: Dark side of the mood

PostPosted: Sun Oct 21, 2007 10:05 am    Post subject: Reply with quote

Late jumping in, I recon - I've just followed the link from UberLord's signature... :-)

I've been using an alias for purging comments from files. I've put the alias definition in .bash_profile as follows:
.bash_profile:
alias purge="egrep -v '^[[:space:]]*#|^ *$|^$'"

It takes less than a script and is more convenient, IMHO. For now it works only on shell files but if you want to strip off comments à la Samba, just append "|^[[:space:]]*;".

As a suggestion, just put it in /etc/skel/.bash_profile ?
_________________
Gentoo addict: tomorrow I quit, I promise!... Just one more emerge...
1739!
Back to top
View user's profile Send private message
Phredus
n00b
n00b


Joined: 07 Feb 2013
Posts: 47

PostPosted: Sun Jun 29, 2014 10:44 am    Post subject: Thank you for the script Reply with quote

I'm just starting to get deep into Gentoo, I love it!!!

Thank you
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum