Thursday, November 21, 2013

Grep quick reference

grep -r "text" .                 recursive scan for "text" in files
grep -r "text" . --include="*.cpp"
grep -r "text" . --include=*.{cpp,h}  or use multiple --include
grep -r -v "contentpane" . | grep "ntp" // exclude line with "contentpane" and search the result for "ntp"

-A NUM                        After  
-B NUM                        Before
-C NUM or just -NUM Context
e.g.
grep -5 -r "text" .            5 lines before and after the matched text

No comments: