Hello Everyone,
I want to print out the records after and before a certain record. I am able to figure out how to print that particular record but not the ones before and after. Looking for some advice
Thank you
Hello Everyone,
I want to print out the records after and before a certain record. I am able to figure out how to print that particular record but not the ones before and after. Looking for some advice
Thank you
What OS are you on? Some versions of grep support:
grep -A 1 -B 1 [pattern] filename
give you one line before and one line after. Is this what you want?
thanks for the reply jim
im using hp ux 11.3 and the sad part is, i think, grep doesnt support the linux options
sed -n -e '/pattern/{x;1!p;g;$!N;p;D;}' -e h infile
I don't have a pattern..just a condition.
for eg;
when so and so is true then print the lines above and below it..
awk -f d.awk infile
where d.awk:
#/bin/ksh
{ if ($2 == 105) {
print lr;
print $0;
lr=$0;
getline;
print $0;
} else {
lr=$0;
}
}
The example condition in the script is $2==105.
If rdrtx1's suggestion isn't sufficient, stop being vague and specify your condition.
Regards,
Alister