Show a script or config file without comments

sed -e '/^[[:blank:]]*#/d; s/[[:blank:]][[:blank:]]*#.*//' -e '/^$/d' -e '/^\/\/.*/d' -e '/^\/\*/d;/^ \* /d;/^ \*\//d' /a/file/with/comments
Strips comments from at least bash and php scripts. Normal # and // as well as php block comments removes all of the: empty/blank lines lines beginning with # lines beginning with // lines beginning with /* lines beginning with a space and then * lines beginning with */ It also deletes the lines if there's whitespace before any of the above. Add an alias to use in .bashrc like this: alias stripcomments="sed -e '/^[[:blank:]]*#/d; s/[[:blank:]][[:blank:]]*#.*//' -e '/^$/d' -e '/^\/\/.*/d' -e '/^\/\*/d;/^ \* /d;/^ \*\//d'"

2009-11-10 17:47:22

8 Alternatives + Submit Alt

What Others Think

egrep -v "^[[:blank:]]*($|#|//|/\*| \*|\*/)" /etc/some/file Does all the sed version does....
sdadh01 · 659 weeks and 1 day ago
Has anyone got version which also strips multiline-comments, like: /* comment blablabla */ or /* comment blablabla */ ???
alvinx · 659 weeks ago
Say no to struggling every time when doing your homework! Take it easy with
AmandaBrooks · 90 weeks and 4 days ago
Read about the script of config file from here as i know can be of a great source and will offer you a lot that you canto imagine otherwise from other sources at that time of the year. Just see that and let us know.
unkamex · 70 weeks and 2 days ago
You can learn so many such comments through this website that makes all your tasks much easier. This particular group homes in las vegas comment shows a config file without comments. Some other alternatives to these comments are listed out here. Thank you so much for the updates.
Alyssalauren · 44 weeks and 1 day ago ??? ? ????? ????
seofox · 21 weeks ago
seofox · 20 weeks and 1 day ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: