I am a sed novice.  I would like to use sed to delete commented lines in a text file.  In my series of text files, commented lines begin with either the # symbol or the @ symbol (i.e., they are files originally intended for plotting in xmgrace).  Suppose I have the following sample file (called sample.txt):# Comment 1# Another comment# Yet another comment@ More comments@ Still more commentsdata1data2data3I would like to use sed to modify sample.txt, in place, to obtain the following:data1data2data3where there is a blank line between data2 and data3 in both versions of sample.txt.With inspiration from this Stack Overflow question, I came up with this series of (consecutive) commands:sed -i 's/#.*$//' sample.txtsed -i 's/@.*$//' sample.txtwhich give this resulting file:    <blank line>    <blank line>    <blank line>    <blank line>    <blank line>data1data2data3where <blank line> is just a blank line.  (I had to write it this way so that Stack Exchange would format the output correctly.)The problem with the above is that the commented lines are only replaced with blank lines, not deleted altogether. Another possibility of (consecutive) commands is:sed -i 's/#.*$//' sample.txtsed -i 's/@.*$//' sample.txtsed -i '/^$/d' sample.txtfrom which I obtain the following output:data1data2data3The above is, however, also wrong because the blank line between data2 and data3 has not been preserved (I am incorrectly deleting all blank lines, indiscriminately).  How do I just delete the commented lines?I am running Ubuntu Linux.  Thanks for your time!
Deleting commented lines in a text file using sed
text processing;sed
Use the sed delete command sed -i '/^[@#]/ d' sample.txtIf you need to account for leading space characters:sed -i '/^\s*[@#]/ d' sample.txt