Running sed and counting number of lines processed

/bin/sed -n ';4757335,$ p' | wc -l
/bin/sed -n ';4757335,$ p' | egrep "Failed" | egrep -c "PM late arrrival"

how can i combine the above two sed commands into one? i want to count the number of lines between the specified line number and the end of the file. AND and i want to count how many lines contain a specified set of strings within those lines.

i dont want to run these sed commands separately because they would add greatly to the time it takes for the script to complete.

I think using awk is the best option here:

awk 'NR>4757335&&/Failed/&&/PM late arrrival/{c++}NR>4757335{d++}END{print c,d;}' filename
1 Like

wonderful!!! i have yet to test it, but could you please explain your beautiful awk command to me? please????

SkySmart, please test it and let me know if it is giving the desired o/p, I will explain the code.

it works. the command returns two numbers:

35300 313306

NR>4757335&&/Failed/&&/PM late arrrival/ - Lines greater than line number: 4757335 and matches pattern: Failed and matches pattern PM late arrrival

{c++} - Increment variable: c for lines that matches all 3 conditions above.

NR>4757335 - Lines greater than line number: 4757335

{d++} - Increment variable: d for lines that matches condition above.

END{print c,d;} - In the end print value of variables: c and d

1 Like