Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Displaying the first two lines

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi all!

The file looks like this (a portion of it):
------------------------------------------------
Packet Number 1
ETH: ====( 60 bytes received on interf
ETH: [ 00:10:b5:e4:c0:bf -> 00:06:2
IP: < SRC = 167.10.10.83 >
IP: < DST = 167.10.10.221 > (ut
TCP: <source port=1292, destination

Packet Number 2
ETH: ====( 188 bytes transmitted on in
ETH: [ 00:06:29:c5:2c:ff -> 00:10:b
IP: < SRC = 167.10.10.221 > (ut
IP: < DST = 167.10.10.83 >
TCP: <source port=23(telnet), desti
TCP: 00000000 2d2d2d2d 2d2d2d2d 2d
TCP: ********
TCP: 00000040 2d2d2d2d 2d2d2d2d 2d
TCP: 00000050 20202020 20202020 20
TCP: 00000060 20202020 20417469 76
TCP: 00000070 61636520 6e612049 6e
TCP: 00000080 20656e31 0d0a
and so on...-------------------------------

What I need to do (and still couldn´t manage to do that) is to get, let´s say, the first two lines of EACH protocol instance. Like, From ETH I need the 1st and 2nd line, from IP I need the 1st and 2nd line and so on...this file will be displayed to end-users, with only the minimum details about a trace on a ETH interface...

Thanks guys!
Jeffo.
 

Hi, jf_moreira!

I didn't quite understand your question, but I suggest you this awk semisolution:

/^Packet/ { print &quot;&quot;; print }
/^ETH/ { print }
/^IP/ { print }


Maybe you get a better idea.

Bye!

KP.
 
Hi Jeffo,


awk '

{
if (($0 ~ /^Packet/)&&(!flag)) {
print
flag = 1
getline
}

if ($0 ~ /^ETH:/) {
if (count1 < 2) {
print
++count1
next
}
}

if ($0 ~ /^IP:/) {
if (count2 < 2) {
print
++count2
next
}
}

if ($0 ~ /^TCP:/) {
if (count3 < 2) {
print
++count3
next
}
}

if (flag) {
print &quot;&quot;
flag = count1 = count2 = count3 = 0
}

}' inputfile > outputfile


Hope this helps you!



flogrr
flogr@yahoo.com

 
Krunek and Flogrr:

The last reply did the job better!
Thank you for the help. I´ll stick with these very useful forums!

[ ]s!
Jeff.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top