You want to delete lines that start with a #
and to remove a #
and any following characters anywhere else on a line. That description practically defines what the sed
script should look like:
sed -e '/^#/d' -e 's/[[:space:]]*#.*//' text0.txt
This removes any spaces before the #
at the end of a line too. You could combine that into one argument if you insist:
sed '/^#/d; s/[[:space:]]*#.*//' text0.txt
Personally, I think it's easier to read the separate operations when they're in separate arguments, but that's a choice you can make for yourself.
Note that there is no need to run two (or more) commands; one is sufficient.