DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Remove Comments From A File
Remove all comment lines from a file.
sed -e '/^#/d' $1 | more
or to output it to a new file
sed -e '/^#/d' $1 > $1.nocomments






Comments
Joao Limberger replied on Fri, 2012/10/26 - 3:01pm
To delete just the '#' and keep the sha-bang... you can try this:
awk '{ if( ($0 !~ /^ *#/) || ($0 ~ /^ *#!/) ) print $0 ; else {gsub(/^ *#/ , "" ); print } } ' teste.sh
Where teste.sh is the script you want to strip the '#'
Snippets Manager replied on Mon, 2009/03/23 - 6:44am
grep -E "^[[:blank:]]*#" MyBashScript.sh to read all comments (but inlines).Snippets Manager replied on Sat, 2007/11/10 - 1:43am
Snippets Manager replied on Sat, 2007/11/10 - 1:43am
Snippets Manager replied on Thu, 2007/06/21 - 1:54pm