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

How to use grep efficiently?

If you have xargs installed on a multi-core processor, you can benefit from the following just in case someone is interested. Environment: Processor: Dual Quad-core 2.4GHz Memory: 32 GB Number of files: 584450 Total Size: ~ 35 GB Tests: 1. Find the necessary files, pipe them to xargs and tell it to execute 8 instances. … Read more

Git search all diffs

git log is generally the command to use when examining commit history. git log –grep can be used to search for regular expressions in the commit message. What you are after is git log -S which searches the commit content simply or git log -G which searches it with a regular expression: -S<string> Look for … Read more

“grep” offset of ascii string from binary file

grep –byte-offset –only-matching –text foobar filename The –byte-offset option prints the offset of each matching line. The –only-matching option makes it print offset for each matching instance instead of each matching line. The –text option makes grep treat the binary file as a text file. You can shorten it to: grep -oba foobar filename It … Read more