alonisser
alonisser

Reputation: 12068

grepping a not matching pattern with a pattern file and data from a pipe

I have an ignore.txt file:

cat ignore.txt
clint

when I do:

pip freeze | grep -v -f ignore.txt

I get:

GitPython==0.3.2.RC1  
Markdown==2.2.1  
async==0.6.1  
clint==0.3.1  
gitdb==0.5.4  
legit==0.1.1  
push-to-wordpress==0.1  
python-wordpress-xmlrpc==2.2  
smmap==0.8.2 

but when I do:

pip freeze | grep -v clint

I do get the correct output:

GitPython==0.3.2.RC1
Markdown==2.2.1
async==0.6.1
gitdb==0.5.4
legit==0.1.1
push-to-wordpress==0.1
python-wordpress-xmlrpc==2.2
smmap==0.8.2

How can I achieve that with grep and command line tools?

Clarfication Edit: I use windows with cygwin so I believe this is GNU grep 2.6.3 (from grep --version)

Upvotes: 1

Views: 416

Answers (1)

Andrea
Andrea

Reputation: 12934

Your syntax looks correct and works on my system. There may be a problem with your ignore.txt file. In particular, check that:

  • there are no leading or trailing spaces, tabs and the like around the word you are trying to filter (as suggested by Kent above)
  • the file has Unix line endings
  • the file is terminated by a single newline

About the latter, the Single Unix Specification says:

Patterns in pattern_file shall be terminated by a <newline>.

Which means that a file with no terminator, or with a different terminator (e.g. CR LF), might behave unexpectedly (though that might be system-dependent).

Upvotes: 1

Related Questions