[lug] Unix help required(i guess results will come using sed and awk)

Doug Shaw shawd at pcisys.net
Sun Apr 15 06:33:29 MDT 2001


>Say i have a file(version.txt)  in which the content is 
>//aggregation/storm/main/modules/YODLEE/HotMail.pm#3 - updating
>D:\src\aggregation\stomr\main\modules\YODLEE\HotMail.pm
>//aggregation/storm/main/modules/YODLEE/HtmlDocument.pm#2 - updating
>D:\src\aggregation\stomr\main\modules\YODLEE\HtmlDocument.pm
>//aggregation/storm/main/modules/YODLEE/YahooMail.pm#1 - updating
>D:\src\aggregation\stomr\main\modules\YODLEE\YahooMail.pm
>//aggregation/storm/main/modules/YODLEE/HtmlTable.pm#4 - updating
>D:\src\aggregation\stomr\main\modules\YODLEE\HtmlTable.pm
>
>Now i use this content ( cat <filename>) and get a output in the following
>form in a file(results.log)
>
>Source code updated: //aggregation/storm/main/modules/YODLEE/HotMail.pm#3
>Source code updated:
>//aggregation/storm/main/modules/YODLEE/HtmlDocument.pm#2
>Source code updated: //aggregation/storm/main/modules/YODLEE/YahooMail.pm#1
>Source code updated: //aggregation/storm/main/modules/YODLEE/HtmlTable.pm#4
>
>using "cat version.txt | awk '/[A-Z,a-z,0-9]/ { print "Source code
>updated:",$1}' | tee -i ~prakash/test/results.log"    
>
>
>Instead of getting the format in the above form , i want the format in
>following way
>Source code updated: HotMail.pm
>Source code updated: HtmlDocument.pm
>Source code updated: YahooMail.pm
>Source code updated: HtmlTable.pm

There's almost certainly a cleaner way to do this, but this works:

cat version.txt | grep -v '^//' | awk -F\\ '/[A-Z,a-z,0-9]/ {print "Source
code updated:",$8}'

Then pipe it through to your tee statement.

The grep filters out the lines that begin with // and passes only the D:\
lines to awk.  The -F on the awk command defines the field delimiter, which
as a double-backslash in the shell is actually passed as a single backslash
to awk.  When the backslash is your field delimiter, the filename you seek
becomes the 8th parameter in the line of input.

This awk statement will work assuming that all of your files are at the
same depth in your directory tree (i.e. other backslashes in the path will
cause awk to return the wrong field).

If you weren't keen on the "source updated: filename" text on each line,
you can generate just the list of filenames like so:

grep '\\' version.txt | cut -d\\ -f8

Doug





More information about the LUG mailing list