Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

printing FILENAME before the block of text between two patterns

17 views
Skip to first unread message

TonyG

unread,
Sep 9, 2013, 10:01:26 PM9/9/13
to
I use a simple awk expression to print blocks of lines between two patterns:

awk '/pattern1/,/pattern2/' file

and would like to add current FILENAME before each block (one per file). The following doesn't work, since it prints FILENAME after each line...:

awk '{print FILENAME} /pattern1/,/pattern2/' file

Using nextfile doesn't help... What's the proper syntax?

TonyG

unread,
Sep 9, 2013, 10:46:11 PM9/9/13
to
I'm replying to myself (but there must be a simpler way than my wife has suggested... :-))

$for i in file; do print $i; awk '/pattern1/,/pattern2/' $i; print; done

:-)
0 new messages