I ran into a problem while trying to grep a file that contains the following:
@abc abc abc @abc@ @abc@ @abc@ acb abc@ assd dsasd abc@
I tried various grep commands, but there was a problem and abc@ or @abc were caught as whitespace in my regexps. I want the output, in general, to simulate the following script's output (only the "Good" ones):
for res in $(grep -F 'abc' test.txt); do if [[ ! $res == *@* ]]; then echo $res is good; else echo $res is bad; fi; done
No -P needed; -E is sufficient:
grep -E '(^|\s)abc(\s|$)'
or even without -E:
After some time with Google I asked on the ask ubuntu chat room.
A user there was king enough to help me find the solution I was looking for and i wanted to share so that any following suers running into this may find it:
grep -P "(^|\s)abc(\s|$)" gives the result I was looking for. -P is an experimental implementation of perl regexps.
abc and then using filters like
grep -v '@abc' (this is far from perfect...) should also work, but my patch does something similar.