Computing.Net > Forums > Solaris > How to grep (say)last-3 and next-3

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

How to grep (say)last-3 and next-3

Reply to Message Icon

Name: Sujan (by Sujan Banerjee)
Date: November 5, 2008 at 23:03:34 Pacific
OS: Sun-OS
CPU/Ram: 2GB
Product: 5.8
Comment:

Hi All,

OS-Type=Sun-OS 5.8 Sparc9 Processor

Can I grep the previous 4 lines and next 4 lines of a matched pattern(context grep)?
For example here we need to monitor logs of live traffic.The data obtained from
"tail -f LiveTrafficData.log" looks something like this:-

Sender-ip=10.123.32.34 //Useful Info
Junk Parameter=blah
Blah Parameter=more blah
Packet-state=start //Useful Info
Policy-type=test-value-policy //Useful Info
Some more blah
blah blah
user-profile-type=host
user-location=njs-234 //Useful Info
....
...
Similar sort of repetitive data
--
Now here the lines which are of concern to me are only policy-type,packet-state,
service-ip and user-location,i.e., I need to ascertain sender-ip and
user-location only and only when Policy-type=<desired pattern> AND
Packet-state=<desired pattern2>.

Also note it is from live traffic, so we need to work on "tail -f"
of whatever log we are getting.

Any help is welcome.

Thanks and Regards.

BTW,I forgot to tell on this OS,there is no "grep -A num" or "cgrep" or "vmsgrep".Also it is live data caught by "tail -f",so need to work on Standard Input and not any file.



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: November 6, 2008 at 11:05:07 Pacific
Reply:

The context script was discussed in this thread:

http://www.computing.net/answers/un...


0
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: How to grep (say)last-3 and next-3

how to make multi boot SunOs and Win98 www.computing.net/answers/solaris/how-to-make-multi-boot-sunos-and-win98/842.html

how to configure NIC www.computing.net/answers/solaris/how-to-configure-nic/581.html

How to print in a C program www.computing.net/answers/solaris/how-to-print-in-a-c-program/4718.html