Mohammedz.com

For Linux and Shell scripting.


2 Comments

How can I remove all line starting with hash (#)

To remove all lines starting with hast sign (#) from a file, try this:
sed /^#/d filename

The above command will remove all line starting with # from its output. If you want to write the output to another file, use o/p redirection >
sed /^#/d filename > newfile

But, if you want to over write the file with new o/p, use -i option with sed.
sed -i /^#/d filename

Regards,

Mohammed.