Find all files containing a string but NOT containing another.
Believe it or not, this was quite a challenge. I tried to use precedent and subsequente regular expressions in UltraEdit for this but UltraEdit’s regex is quite dumb. So I came up with good-old shell:
find . -name "*html" | xargs grep -l 'StringA' | xargs grep -L 'StringB'
Beginning from the current directory (“find .”) this finds all html files containing the string ‘StringA’ in the first grep statement but NOT the ones containing the string ‘StringB’ in the second grep statement. If any nerd could tell me how to do this more easily, this would bring light in my day-to-day life. 🙂 Actually this shell piping is pretty fast. I ran this over hundreds of html files in half of a second. Using PERL you’d need 30 lines and half an hour, I think.
To do this in Windows, you’ll need gfind, xargs and GNU grep (see UnxUtils website)