Another one I've done that always stuck with me was grep '^[^;]' filename. I can't speak to its portability though!
–
JodieCDec 8 '12 at 13:57

@JodieC, that's portable but also removes empty lines (Which is often desired). The standard equivalent of egrep is grep -E. One can also use grep -ve '^[;#]' -e '^//'
–
Stéphane ChazelasJan 28 '13 at 12:30

+1 for perl, although the cat and the -l are both redundant, so a simpler invocation is perl -ne 'print unless /^;/' data.txt
–
Simon WhitakerDec 8 '11 at 3:59

@Simone Whitaker, yes, you are right - it is just a habit to write it the way i write, and it worth to mention it.
–
shabuncDec 8 '11 at 4:18

1

Sure thing. In fact, I think cat works fine in these examples if you consider it as a proxy for the more generic "anything generating text on STDOUT". Unix pipes are the best thing since sliced bread, imho. :)
–
Simon WhitakerDec 8 '11 at 9:43

Here's one that I use, just substitute ';' with the comment character (e.g. '#' for many UNIX service configuration files):

grep -Ev '^[[:space:]]*;|^$' chan_dahdi.conf.sample | sed 's/;.*$//'

That gets rid of all whole-line comments (even if they have leading whitespace), and any comments that end non-comment lines, and succinctly removes blank lines from the output as well. This may be possible without the pipeline (my sed- or awk-fu is admittedly not great), but it's so easy for me to understand (and remember), I figured I'd post it here.