Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Discussion & Documentation Documentation, Tips & Tricks
  • Search

TIP Strip comments when posting config files

Unofficial documentation for various parts of Gentoo Linux. Note: This is not a support forum.
Post Reply
Advanced search
41 posts
  • Previous
  • 1
  • 2
Author
Message
jmbsvicetto
Moderator
Moderator
User avatar
Posts: 4735
Joined: Wed Apr 27, 2005 4:33 pm
Location: Angra do Heroísmo (PT)

  • Quote

Post by jmbsvicetto » Tue Feb 14, 2006 7:40 pm

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
Top
Joe User
n00b
n00b
User avatar
Posts: 10
Joined: Sun Mar 21, 2004 10:54 am
Location: Germany
Contact:
Contact Joe User
Website

  • Quote

Post by Joe User » Sun May 07, 2006 10:35 am

This version strips out comment and blank lines:

Code: Select all

sed '/^[[:space:]]*\([#;].*\)*$/d'
PayPal.Me/JoeUser ● FreeBSD Remote Installation
Top
al
Guru
Guru
User avatar
Posts: 304
Joined: Thu Dec 26, 2002 10:33 pm
Location: Scotland
Contact:
Contact al
Website

  • Quote

Post by al » Thu Jun 15, 2006 11:40 am

x1jmp wrote:Thanks for this tip with sed!

My version is this, which also deletes lines with ";", like the smb.conf

Code: Select all

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
Top
chrismortimore
l33t
l33t
User avatar
Posts: 721
Joined: Sat Dec 03, 2005 1:14 am
Location: Edinburgh, UK

  • Quote

Post by chrismortimore » Wed Aug 09, 2006 6:13 pm

All these look very complex...

Code: Select all

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
Top
tomk
Bodhisattva
Bodhisattva
User avatar
Posts: 7221
Joined: Tue Sep 23, 2003 1:41 pm
Location: Sat in front of my computer

  • Quote

Post by tomk » Sat Nov 25, 2006 12:10 am

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 | [topic=119906]Answer[/topic] | [topic=28820]Report[/topic] | [topic=160179]Strip[/topic]
Top
bunkacid
Tux's lil' helper
Tux's lil' helper
Posts: 111
Joined: Tue Jan 11, 2005 2:04 am
Location: Laguna Hills, CA
Contact:
Contact bunkacid
Website

  • Quote

Post by bunkacid » Tue Dec 19, 2006 1:25 pm

thanks, i only just found this useful "one liner" to include in my ~/bin
Top
hielvc
Advocate
Advocate
Posts: 2805
Joined: Fri Apr 19, 2002 5:55 pm
Location: Oceanside, Ca

  • Quote

Post by hielvc » Sat Jan 13, 2007 5:40 pm

Shortest

Code: Select all

 sed '/^#\|^$/d' /etc/make.conf.example
An A-Z Index of the Linux BASH command line
Top
nanafunk
n00b
n00b
Posts: 36
Joined: Wed Jun 29, 2005 2:03 am

  • Quote

Post by nanafunk » Mon Jan 15, 2007 12:48 am

Code: Select all

[%] cat a
#comment1
 #comment2
[%] sed '/^#\|^$/d' a
 #comment2
Top
hielvc
Advocate
Advocate
Posts: 2805
Joined: Fri Apr 19, 2002 5:55 pm
Location: Oceanside, Ca

  • Quote

Post by hielvc » Tue Jan 16, 2007 12:22 am

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
Top
thomasvk
Guru
Guru
Posts: 597
Joined: Sat Mar 19, 2005 6:53 pm

  • Quote

Post by thomasvk » Sat Jan 27, 2007 1:03 pm

A lot of diffent ones,... but which one is the best? :P :roll:
Top
Sakkath
Apprentice
Apprentice
Posts: 198
Joined: Sun Nov 06, 2005 4:13 am
Location: Pawtucket, RI
Contact:
Contact Sakkath
Website

  • Quote

Post by Sakkath » Fri Feb 09, 2007 1:53 pm

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.
Top
timeBandit
Bodhisattva
Bodhisattva
User avatar
Posts: 2719
Joined: Fri Dec 31, 2004 1:54 am
Location: here, there or in transit

  • Quote

Post by timeBandit » Sat Feb 10, 2007 5:56 pm

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, [topic=160179]strip[/topic] comments, [topic=515888]mark[/topic] solved, [topic=119906]help[/topic] others.
Top
Sakkath
Apprentice
Apprentice
Posts: 198
Joined: Sun Nov 06, 2005 4:13 am
Location: Pawtucket, RI
Contact:
Contact Sakkath
Website

  • Quote

Post by Sakkath » Sat Feb 10, 2007 6:15 pm

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.
Top
carpman
Advocate
Advocate
Posts: 2202
Joined: Thu Jun 20, 2002 2:42 pm
Location: London - UK

  • Quote

Post by carpman » Mon Jun 11, 2007 10:28 am

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
Top
VinzC
Watchman
Watchman
User avatar
Posts: 5100
Joined: Sat Apr 17, 2004 1:51 pm
Location: Dark side of the mood

  • Quote

Post by VinzC » Sun Oct 21, 2007 10:05 am

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:

Code: Select all

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!
Top
Phredus
n00b
n00b
User avatar
Posts: 47
Joined: Thu Feb 07, 2013 12:28 pm

Thank you for the script

  • Quote

Post by Phredus » Sun Jun 29, 2014 10:44 am

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

Thank you
Top
Post Reply

41 posts
  • Previous
  • 1
  • 2

Return to “Documentation, Tips & Tricks”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy