
August 5th, 2009, 02:55 AM
|
|
Contributing User
|
|
Join Date: Feb 2004
Location: London, England
|
|
You can do this more easily with sed:
sed -n '/reference1/,/reference2/p' filename
The -n flag suppresses the default behaviour of printing every line.
/regex1/,regex2/p prints the lines from the one that matches regex1 up to the one that matches regex2.
Your awk program should also work I think, but is a bit verbose. You can simplify it to this:
Code:
/reference1/ {doprint = 1}
/reference2/ {doprint = 0}
{ if (doprint) {print $0}}
Variables are magically created when first used and initialised to 0 or "" depending on the context.
You can match lines using /regex/ instead of using the match function.
Dave
|