The following grep phrase lists all.exe and.html files in the current directory and subdirectories successfully.
ls -R |grep -E .*[\.exe]$\|.*[\.html]$
How can I flip this result to list only the files that aren’t.html or.exe? (In other words,!=.)
Asked by sMaN
Use the -v or —invert-match command-line options.
ls -R |grep -v -E .*[\.exe]$\|.*[\.html]$
Answered by Eric Fortis
You can also use search to accomplish the same goal:
find . -type f \( -iname "*" ! -iname ".exe" ! -iname ".html"\)
More info here.
Answered by darioo
To reverse the results, use the grep command with the -v option.
Answered by Rob Sobers
The -v option to grep achieves inversion, as previously described. Let me add the (hopefully funny) caveat that you could have figured this out by grepping through the grep help text yourself:
grep --help | grep invert
Answered by jmd_dk
grep "subscription" | grep -v "spec"
Answered by Anja Ishmukhametova
Post is based on https://stackoverflow.com/questions/4373675/how-to-invert-a-grep-expression