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.


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?

  • The v gives an error. Could you correct your post?
    – vinc17
    Jul 8, 2014 at 23:30

1 Answer 1


With shells having process substitution like bash and zsh:

grep -f <(grep -v '^#' include) file > out
  • But, oh dear. I can't get the "exclude" part to work. That is,
    – user618
    Jul 9, 2014 at 2:55
  • What "exclude" part?
    – vinc17
    Jul 9, 2014 at 7:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.