How to make “grep” read patterns from a file?
grep -v -f pattern_file
grep -v -f pattern_file
You can use multiple –include flags. This works for me: grep -r –include=*.html –include=*.php –include=*.htm “pattern” /some/path/ However, you can do as Deruijter suggested. This works for me: grep -r –include=*.{html,php,htm} “pattern” /some/path/ Don’t forget that you can use find and xargs for this sort of thing too: find /some/path/ -name “*.htm*” -or -name “*.php” … Read more
You can use the -i flag which makes your pattern case insensitive: grep -iF “success…” file1 Also, there is no need for cat. grep takes a file with the syntax grep <pattern> <file>. I also used the -F flag to search for a fixed string to avoid escaping the ellipsis.
This looks like a behavior difference in the handling of \s between grep 2.5 and newer versions (a bug in old grep?). I confirm your result with grep 2.5.4, but all four of your greps do work when using grep 2.6.3 (Ubuntu 10.10). Note: GNU grep 2.5.4 echo “foo bar” | grep “\s” (doesn’t match) … Read more
You’re looking for a non-greedy (or lazy) match. To get a non-greedy match in regular expressions you need to use the modifier ? after the quantifier. For example you can change .* to .*?. By default grep doesn’t support non-greedy modifiers, but you can use grep -P to use the Perl syntax.
If you want to find all commits where the commit message contains a given word, use $ git log –grep=word If you want to find all commits where “word” was added or removed in the file contents (to be more exact: where the number of occurrences of “word” changed), i.e., search the commit contents, use … Read more
Do the following: grep -rnw ‘/path/to/somewhere/’ -e ‘pattern’ -r or -R is recursive, -n is line number, and -w stands for match the whole word. -l (lower-case L) can be added to just give the file name of matching files. -e is the pattern used during the search Along with these, –exclude, –include, –exclude-dir flags … Read more
What about the following: awk -F, ‘(NR==FNR){a[$1];next}!($1 in a)’ blacklist.csv candidates.csv How does this work? An awk program is a series of pattern-action pairs, written as: condition { action } condition { action } … where condition is typically an expression and action a series of commands. Here, the first condition-action pairs read: (NR==FNR){a[$1];next} if … Read more
Use whole word option: grep -c -w aaa $EAT_Setup_BJ3/Log.txt From the grep manual: -w, –word-regexp Select only those lines containing matches that form whole words. The test is that the matching substring must either be at the beginning of the line, or preceded by a non-word constituent character. As noted in the comment -w is … Read more
This is because {} are special characters and they need to handled differently to have this special behaviour. Otherwise, they will be treated as literal { and }. You can either escape like you did: $ echo “@NS500287” | grep ‘^@NS500[0-9]\{3\}’ @NS500287 or use grep -E: $ echo “@NS500287” | grep -E ‘^@NS500[0-9]{3}’ @NS500287 Without … Read more