Pattern Search using AWK

Hi All,

I have the below file data.txt.Using awk i want to grep all the zone data.Form the below command i can extact data upto of zone i give but i want it should print until next pattern.

awk '/^Total Collection  /{c=5;next}c-->0' zin45srs08.tools_utilization

instead of c=5 is it possible to give next pattern.

##########################

cat data.txt
Total Collection = $10291 {Fri May  8}
zone7   4500
zone8   3545
zone1   1200
zone0   900
Total Collection = $11847 {Sat May  9}
zone1   2800
zone3   2800
zone6   2567
zone8   2300
zone9   1200
zone12  90
zone11  90

############################

If you want to print all the zones:

grep "^zone" file

To print a specific collection (i.e. the first one) you can do something like:

awk '/^Total Collection/ && /\$10291/ {c=1;next}c && /^Total Collection/{c=0}c' file

Hi Franklin,

Thanks for your reply.Query is, i am searching on Total collection so need to print all the information between them.Total collection may be n & my zones will also vary.

Regards

Ankit

 
nawk ' BEGIN {FS="Total\ Collection"} {print $1}' /tmp/myfile

Can you explain what's wrong with the solutions above?

If you don't get the correct output, post a better input file and the desired output.

Firsly nawk is not running on my system & if i m using without nawk its print all information.

Regards

Ankit