deleting last n lines from a output

Friends, I am executing this command in solaris sar -d 3 3 | awk 'NR > 2 { if ($1 !~ /,.+/) print }' | egrep -v "nfs[0-9]|device" . Now i want to delete the last two lines of my output as they are records of average which i don't want. can some one pls give me some idea on how to proceed.

try:

 sar -d 3 3 | awk 'NR > 2 { if ($1 !~ /,.+/) print }' | egrep -v "nfs[0-9]|device" | sed -n '/Average/!p;/Average/q;'

as generic solution to only print lines until Averages

HTH,

not working :frowning:

Works flawless on my Linux box. Mind to share what is not working?

this is a solaris box. And its working but the sed has to be put first . this is the form in which its working sar -d 3 3 | sed -n '/Average/!p;/Average/q;' | awk 'NR > 2 { if ($1 !~ /,.+/) print }' | egrep -v "nfs[0-9]|device".

Lesson learnt is East or west. Linux the best

This is an awful way of using *nix command. As I already suggested in my answer your earlier post you can do all that without that pipe construction.

sar gives another o/p on my box but I guess that something like this will work:

sar -d 3 3 | awk '!/device|nfs[0-9]|^,.+|Average/ {printf }'

Way too many pipes for my taste....

sar -d 3 3 | nawk '!/Average|nfs[0-9]|device/ && FNR>2 && $1 !~ /,.+/ && NF'

For using a fixed number of lines (ie. 2) you do not want to print from the end of a file/input you could also try (for further use):

head -$((`wc -l < infile`-2)) infile