I am using following command to get the search value and previous line value.
sed -n -e 'N; /resize/p' alter_PU1M03.log
Please let me know how can I get the search string + previous two values and combine the output to one line.
I am using HPUX 11.11
awk '/resize/{printf "%s %s %s\n", last2, last1, $0 }
{ last2 = last1
last1 = $0
}' FILE
Thanks it works, I really appreciate your help.
awk:
nawk '{
if(index($0,"pattern")!=0)
print l2" "l1" "$0
else
{
l2=l1
l1=$0
}
}' filename
sed:
pat=$1
sed -n '/'$pat'/ !{
H
}
/'$pat'/ {
H
x
s/\(.*\)\n\(.*\)\n\(.*\)\n/\2 \3/
p
}' filename