Jun 282012

A small, handy way to find stuff easily via commandline in a set fo files:

grep -inHR “search term” –include=’*.xml’ *

  • i ignore-case
  • n line number
  • H Print the filename for each match
  • R  –include=<Pattern> Recurse in directories only searching file matching <Pattern>
  • * The preceding item will be matched zero or more times.

in all sub folders in a given folder all files that end with xml and contain search term are listed in the output with name and the matching line including the line number.

I used to use file search in ultraedit, however my license expired and ultraedit on mac is not quite as powerful as its Windows equivalent so I didn’t bother to renew. Grep is my new best friend. 

Update: sweet example:

grep -inRH “4.7.0″ –include=’*pom.xml’ * -B2

is looking in pom files that contain the given string and prints out 2 lines before.

Popularity: 4% [?]

Tags: , , ,