awk to grab data in range then search for pattern

im using the following code to grab data, but after the data in the range im specifying has been grabbed, i want to count how many instances of a particular pattern is found?

awk 'BEGIN{count=0} /parmlib.*RSP/,/seqfiles.*SSD/ {print; count++ } /103 error in ata file/ END { print count }' /var/log/xferlog

i inserted the bolded because that's my attempt to search for the string "103 error in ata file" within the range of data i specified.

How about (untested as no test data available)

awk '/parmlib.*RSP/,/seqfiles.*SSD/ {print; count++; if (/103 error in ata file/) cnt2++} END { print count, cnt2 }' /var/log/xferlog

Hello SkySmart,

As you have not shown sample Input_file to us, so based on your tried code, could you please try following and let me know if this helps you.

awk 'BEGIN{count=0} /parmlib.*RSP/,/seqfiles.*SSD/ {if($0 ~ /103 error in ata file/){count++}; } END { print count }'  Input_file

Off course above is not tested at all.

Thanks,
R. Singh

1 Like

this works. thank you

---------- Post updated at 09:12 AM ---------- Previous update was at 09:09 AM ----------

when i run this, it prints out an output even when the string i specified to search for is not found.

the output it prints out is from the first search range.

i got this to work by using Rav's example.

thank you!