On Wednesday 28,December,2011 01:12 AM, Greg Wooledge wrote:
awk '/^step$/ {getline; step=$0} END {print step}'
On Wed, Dec 28, 2011 at 01:33:53AM +0800, lina wrote:
sorry, too concise for me to be able to put into practice about the
bunch of files part.
$ more try.sh
#!/usr/bin/awk
awk 'BEGIN{
/^step$/
}
{
getline;
step=$0
}
END{
print step
}' $0
You do not want to use BEGIN here. You want the /^step$/ pattern to be
matched against each line of input.
If you want it to be an "awk script", then do this:
#!/usr/bin/awk
/^step$/ { getline; step=$0 }
END { print step }
Both this, and my original, only operate on *one* file at a time. If
you want to run it against multiple files, then you either need to
rewrite it, or just run it from a shell loop:
for f in a_*.txt; do
awk '....' "$f"
done