Read .txt file and dropping lines starting with #

Hi All,

I have a .txt file with some contents as below:

Hi How are you?
# Fine and you?

I want a script file which reads the .txt file and output the lines which does not start with #.

Hi How are you?

Help is highly appreciated.

sed '/^#/d' myFile.txt

Another way:

sed -n '/^#/!p' infile
grep -v '^#' infile

Hi,

Thanks for the quick reply.
As posted earlier,
I need to delete all the blanks lines and any line staring with a special character such as # or , or _

Where was it posted earlier? I don't see it.
You can modify any of the solutions to adjust for your new requirements.

How about this:-

egrep -v "^#|^_|^$|^ *$" filename

To explain, this will get all lines that do not match any of the expression. The expression is explained as:-

You could then append either a redirect to create a new file (don't try to overwrite the source file) or perhaps a pipe to another process, e.g.

egrep -v "^#|^_|^$|^ *$" filename|while read line
do
   echo "I've got a line to do something whizzy with"
done

I hope that this helps, but please post back if I've missed the point.

Robin
Liverpool/Blackburn
UK