grep recursive filename matching (grep -ir “xyz” *.cpp) does not work

Grep will recurse through any directories you match with your glob pattern. (In your case, you probably do not have any directories that match the pattern “*.cpp”) You could explicitly specify them: grep -ir “xyz” *.cpp */*.cpp */*/*.cpp */*/*/*.cpp, etc. You can also use the –include option (see the example below) If you are using … Read more

ack misses results (vs. grep)

ack is peculiar in that it doesn’t have a blacklist of file types to ignore, but rather a whitelist of file types that it will search in. To quote from the man page: With no file selections, ack-grep only searches files of types that it recognizes. If you have a file called foo.wango, and ack-grep … Read more

Read expression for grep from standard input

Use -f with a single dash to denote the standard input: $ echo Content | grep -f – notice.html <meta http-equiv=”Content-Type” content=”text/html; charset=ISO-8859-1″> … Note: This has been tested with GNU grep – I am not sure if it’s specified by POSIX.

How to use non-capturing groups in grep?

“Non-capturing” doesn’t mean that the group isn’t part of the match; it means that the group’s value isn’t saved for use in back-references. What you are looking for is a look-behind zero-width assertion: grep -Po “(?<=syntaxHighlighterConfig\.)[a-zA-Z]+Color” file

Using grep with regular expression to filter out matches

The problem is that by default, you need to escape your |’s to get proper alternation. That is, grep interprets “foo|bar” as matching the literal string “foo|bar” only, whereas the pattern “foo\|bar” (with an escaped |) matches either “foo” or “bar”. To change this behavior, use the -E flag: tail -f logFile | grep -vE … Read more

Grep for beginning and end of line?

The tricky part is a regex that includes a dash as one of the valid characters in a character class. The dash has to come immediately after the start for a (normal) character class and immediately after the caret for a negated character class. If you need a close square bracket too, then you need … Read more