Remove all lines which start with #

Oracle Linux 6.4/Bash

I have a file like below. I want to remove all lines which start with # character. Can I do this vi editor ? If not , which other utility can I use for this ?

# This is a test script
CUSER=`id |cut -d"(" -f2 | cut -d ")" -f1`
# Some text
CDATE=`date +%y%m%d` ## get the date
app_LOG_FILE=/home/manh/appsLogs/RMANFullDB-`date +%y%m%d%H%M`.out
#main script

Try (GNU sed):

sed -i.bak '/^\s*#/d' file
1 Like

Cool. Thank you scrutinizer. Any way this can be done from within VI editor ?

Try something like:

:g/^ *#/d
1 Like