Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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.

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |