If you want your script to behave like the ksh itself (ignore the part of a line after a "#" but use the part before it) you could do the following (replace "<spc>" with a literal space, "<tab>" with a tab char):
Code:
script
sed 's/#.*$/;s/^[<spc><tab>]*//;s/[<spc><tab>]*$//;/^$/d' file
content of file
# this is a line with comments
# this too, but starting with blanks
command 1 # this line contains an inline comment
command 2 "#" # this too, but my script would be confused
result
command 1
command 2 "
Alas, the script fails on the second line, but save for such delicacies it works.
bakunin