The following grep expression successfully lists all the .exe and .html files in the current directory and sub directories.
ls -R |grep -E .*[\.exe]$\|.*[\.html]$
How do I invert this result to list those that aren't a .html or .exe instead. (That is, !=
.)
To invert the Grep output , use the -v flag. The -v option instructs grep to print all lines that do not contain or match the expression. The –v option tells grep to invert its output, meaning that instead of printing matching lines, do the opposite and print all of the lines that don't match the expression.
Grep Regular Expression In its simplest form, when no regular expression type is given, grep interpret search patterns as basic regular expressions. To interpret the pattern as an extended regular expression, use the -E ( or --extended-regexp ) option.
The easiest of the two commands is to use grep's -w option. This will find only lines that contain your target word as a complete word. Run the command "grep -w hub" against your target file and you will only see lines that contain the word "hub" as a complete word.
Use command-line option -v
or --invert-match
,
ls -R |grep -v -E .*[\.exe]$\|.*[\.html]$
grep -v
or
grep --invert-match
You can also do the same thing using find
:
find . -type f \( -iname "*" ! -iname ".exe" ! -iname ".html"\)
More info here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With