[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1680
  • Last Modified:

Parse Log File..Get Result line + line after it..AWK ? GREP ? SED ? Regexp ?

I have the following expression

tail -n 100000 xmppd.log | sed -e '/iq type="set" id="iq-id:2/!d'

I need to get the result line(s) + the line directly following the result line...

I.e if Iam searching for xxx in

..... xxx....
.....yyy....
......ccc....

I want to get as as a result

....xxx...
....yyy...
0
http:// thevpn.guru
Asked:
http:// thevpn.guru
  • 2
  • 2
1 Solution
 
xDamoxCommented:
Hi,

This can be done with grep for example say you have the value:

ccc
ccc
xxx
yyy
ccc

You can use the following:

grep -A 1 xxx

This would get the xxx line plus one line after the xxx
0
 
http:// thevpn.guruAuthor Commented:
Yep...I did that allright..however I am not at a new hurdle..how can I display only the last match of grep ?
0
 
xDamoxCommented:
Hi,

You could do something like:

grep -A 1 xxx <file we are parsing> | tail -n 2

0
 
http:// thevpn.guruAuthor Commented:
to match the last line..with grep use..
-m 1
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now