Using GNU Awk
by Marshall on July 20, 2004
I needed to search a VB6 project for instances of a pattern which signifies a data access call. Time to call upon our trusty GNU tools thanks to cygwin.
call DataAccess(True, Conn, 120, "sp_SelectSomeData", Parameter1, Parameter2...)
Say I have a bunch of calls like this one scattered about multiple code documents and I want to know what the 4th parameter in every call is. Using a combination of cat, awk and tr I can obtain a simple list by issuing the command.
cat *.frm | awk -F, '/DataAccess/ { print $4 }' | tr "\"" " " | tr ")" " "
The awk portion of the command wotks like this: -F, sets our field delimiter, /DataAccess/ is a regular expression that you are looking for in the stream, { print $4 } says “Print the 4th field in the line”. A few tr’s to get rid of quotation marks and the stray parenthesis and we have our list.
Leave your comment