Tuesday, May 5, 2009

gnu find and grep: using path patterns to match more than one file extension

Example using Cygwin gnu find, xargs and grep to search for a typo in XSLT and XML files. Note that -iregex matches a pattern in the whole path, and the pattern is a POSIX basic regex:

C:\>find ./ -iregex '.*\.\(xslt\^|xml\)' -type f -print | xargs grep -i "staus"


When find matches a file path, the path is piped to xargs, which hands it off to grep to search for the string "staus" - which I want to replace with "status" (but not here :).

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.