I'd like find lines in files with an occurrence of some pattern and an absence of some other pattern. For example, I need find all files/lines including loom
except ones with gloom
. So, I can find loom
with command:
grep -n 'loom' ~/projects/**/trunk/src/**/*.@(h|cpp)
Now, I want to search loom
excluding gloom
. However, both of following commands failed:
grep -v 'gloom' -n 'loom' ~/projects/**/trunk/src/**/*.@(h|cpp)
grep -n 'loom' -v 'gloom' ~/projects/**/trunk/src/**/*.@(h|cpp)
What should I do to achieve my goal?
EDIT 1: I mean that loom
and gloom
are the character sequences (not necessarily the words). So, I need, for example, bloomberg
in the command output and don't need ungloomy
.
EDIT 2: There is sample of my expectations. Both of following lines are in command output:
I faced the icons that loomed through the veil of incense.
Arty is slooming in a gloomy day.
Both of following lines aren't in command output:
It’s gloomyin’ ower terrible — great muckle doolders o’ cloods.
In the south west round of the heigh pyntit hall
there is a loom in the gloom
- would you want that line printed? Just trying to understand if you're just looking for lines where loom occurs other than as part of gloom or if you really do want to exclude lines containing gloom even when loom appears on it's own elsewhere on the line. Posting some sample input and expected output would help.How do I find lines containing the string "loom" where "loom" is not preceded by the letter "g"
? If you'd posted some sample input and desired output that would have helped a lot. The answer to that question is included in the answers below.loom
without precededg
. (I'm sorry. I started to comment yesterday, but never finished. Accidentally this comment was sent.)