How to invert a grep expression
Use command-line option -v or –invert-match, ls -R |grep -v -E .*[\.exe]$\|.*[\.html]$
Use command-line option -v or –invert-match, ls -R |grep -v -E .*[\.exe]$\|.*[\.html]$
FINDSTR is fairly powerful, supports regular expressions and has the advantages of being on all Windows machines already. c:\> FindStr /? Searches for strings in files. FINDSTR [/B] [/E] [/L] [/R] [/S] [/I] [/X] [/V] [/N] [/M] [/O] [/P] [/F:file] [/C:string] [/G:file] [/D:dir list] [/A:color attributes] [/OFF[LINE]] strings [[drive:][path]filename[ …]] /B Matches pattern if at … Read more
Try this (not sure if it’s the best way, but it works): find . -type f | perl -ne ‘print $1 if m/\.([^.\/]+)$/’ | sort -u It work as following: Find all files from current folder Prints extension of files if any Make a unique sorted list
There are three options, that you can use. -I is to exclude binary files in grep. Other are for line numbers and file names. grep -I -n -H -I — process a binary file as if it did not contain matching data; -n — prefix each line of output with the 1-based line number within … Read more
Use ack. Checkout its –passthru option here: ack. It has the added benefit of allowing full perl regular expressions. $ ack –passthru ‘pattern1’ file_name $ command_here | ack –passthru ‘pattern1’ You can also do it using grep like this: $ grep –color -E ‘^|pattern1|pattern2’ file_name $ command_here | grep –color -E ‘^|pattern1|pattern2’ This will match … Read more
This works for multiple occurrences per line: grep -o string * | wc -l
grep $PATTERN * would be sufficient. By default, grep would skip all subdirectories. However, if you want to grep through them, grep -r $PATTERN * is the case.
Another option is to use find and then pass it through sed. find /path/to/files -type f -exec sed -i ‘s/oldstring/new string/g’ {} \;
Try this little trick to coax grep into thinking it is dealing with multiple files, so that it displays the filename: grep ‘pattern’ file /dev/null To also get the line number: grep -n ‘pattern’ file /dev/null
The comm command (short for “common”) may be useful comm – compare two sorted files line by line #find lines only in file1 comm -23 file1 file2 #find lines only in file2 comm -13 file1 file2 #find lines common to both files comm -12 file1 file2 The man file is actually quite readable for this.