Home > Software engineering >  Mac Terminal not returning correct Patterns with grep
Mac Terminal not returning correct Patterns with grep

Time:08-03

i'm attempting to clean a word list using scripting. Starting out, i'm just trying to remove words with a '.' in them.

I've tried

grep -v "\." wlist_match1.txt

and

grep -v ‘\.’ wlist_match1.txt

and

grep -v \. wlist_match1.txt

It still returns a list of words with '.' in them for all commands. I'm not sure what to do. Even when I grep words I know are in the list, it will return an empty list so it appears grep is not working at all. Any hints?

CodePudding user response:

Suppose we have

$ cat file
1
1.5
2

Then (I'm using /usr/bin/grep to use the MacOS grep, not the GNU grep that occurs earlier in my PATH)

$ /usr/bin/grep -v "\." file
1
2

removed the line with the literal dot.

$ /usr/bin/grep -v \. file

removed all lines -- bare "slash-dot" becomes plain dot, and grep removes any line containing a character.

$ /usr/bin/grep -v ‘\.’ file
1
1.5
2

no lines removed because no lines contain the "fancy" quotes.

Do you not get the same results?

  • Related