Shell – annotate “include” file for grep with comments

grepshell

I do a grep sort that includes certain strings. That is, give me the lines in a file that DO contain certain strings. As in

grep -fv include file  > out

That command looks in file and sends to out every line that matches what is in the file include. No problem with that. Works fine.

BUT

How do I put comments in my include file?

For example, I'd like to annotate that file with some (e.g. #) comments that explain what I'm including. So I'd like for grep to ignore any lines in the include file that start with #. How do I do that?

Best Answer

With shells having process substitution like bash and zsh:

grep -f <(grep -v '^#' include) file > out
Related Question