LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Closed Thread
 
Search this Thread
Old 09-10-2007, 07:20 AM   #1
mruknown1
LQ Newbie
 
Registered: Sep 2007
Posts: 6

Rep: Reputation: 0
awk/perl script for extract data


Hello... i need awk/perl script that can calculate packet size.

for example based on this output, each column have their own meaning
column1=send/received, drop,...
column2= timestamp
column3=node
column4=level
column5=flag
column6=packetID
column7=packettype
column8=packetsize
.....
.....

1. How if i want to calculate total PACKETSIZE RECEIVED by NODE 5 with RTR LEVEL and DSR PACKETTYPE .From here i will try to manipulate the script so i can used it in my research.

2. How if i want to extract this output so i can create a new file that print 2 columns (TIMESTAMP and DSR) when NODE 5 RECEIVED DSR PACKETTYPE with RTR LEVEL.

thank you very much for any help...

s 84.456630640 _5_ AGT --- 0 cbr 512 [0 0 0 0] ------- [5:1 6:1 32 0] [0] 0 1
r 84.456630640 _5_ RTR --- 0 cbr 512 [0 0 0 0] ------- [5:1 6:1 32 0] [0] 0 1
s 84.460452677 _5_ RTR --- 1 DSR 32 [0 0 0 0] ------- [5:255 6:255 32 0] 1 [1 1] [0 1 0 0->0] [0 0 0 0->0]
r 84.461724861 _4_ RTR --- 1 DSR 32 [0 ffffffff 5 800] ------- [5:255 6:255 32 0] 1 [1 1] [0 1 0 0->0] [0 0 0 0->0]
r 84.461724909 _0_ RTR --- 1 DSR 32 [0 ffffffff 5 800] ------- [5:255 6:255 32 0] 1 [1 1] [0 1 0 0->0] [0 0 0 0->0]
r 84.461725322 _6_ RTR --- 1 DSR 32 [0 ffffffff 5 800] ------- [5:255 6:255 32 0] 1 [1 1] [0 1 0 0->0] [0 0 0 0->0]
r 84.461725410 _1_ RTR --- 1 DSR 32 [0 ffffffff 5 800] ------- [5:255 6:255 32 0] 1 [1 1] [0 1 0 0->0] [0 0 0 0->0]
r 84.461725471 _2_ RTR --- 1 DSR 32 [0 ffffffff 5 800] ------- [5:255 6:255 32 0] 1 [1 1] [0 1 0 0->0] [0 0 0 0->0]
s 84.462207082 _6_ RTR --- 2 DSR 44 [0 0 0 0] ------- [6:255 5:255 254 5] 2 [0 1] [1 1 2 5->6] [0 0 0 0->0]
r 84.466670604 _5_ RTR --- 2 DSR 44 [13a 5 6 800] ------- [6:255 5:255 254 5] 2 [0 1] [1 1 2 5->6] [0 0 0 0->0]
SFESTs 84.466670604 _5_ 0 [5 -> 6] 1(1) to 6 [5 |6 ]
s 84.466670604 _5_ RTR --- 0 cbr 548 [0 0 0 0] ------- [5:1 6:1 32 6] [0] 0 1
r 84.472832542 _6_ RTR --- 0 cbr 548 [13a 6 5 800] ------- [5:1 6:1 32 6] [0] 1 1
r 84.472832542 _6_ AGT --- 0 cbr 512 [13a 6 5 800] ------- [5:1 6:1 32 6] [0] 1 1
s 89.865825846 _5_ AGT --- 3 cbr 512 [0 0 0 0] ------- [5:1 6:1 32 0] [1] 0 2
r 89.865825846 _5_ RTR --- 3 cbr 512 [0 0 0 0] ------- [5:1 6:1 32 0] [1] 0 2
SFESTs 89.865825846 _5_ 3 [5 -> 6] 1(1) to 6 [5 |6 ]
s 89.865825846 _5_ RTR --- 3 cbr 548 [0 0 0 0] ------- [5:1 6:1 32 6] [1] 0 2
SSendFailure 89.907170846 _5_ 3 2 5:1 6:1 5->6 2 2 2 2 [|5 6 ]
s 89.912216246 _5_ RTR --- 4 DSR 32 [0 0 0 0] ------- [5:255 6:255 32 0] 1 [1 2] [0 2 0 0->0] [0 0 0 0->0]
r 89.913368448 _0_ RTR --- 4 DSR 32 [0 ffffffff 5 800] ------- [5:255 6:255 32 0] 1 [1 2] [0 2 0 0->0] [0 0 0 0->0]
s 89.913368448 _0_ RTR --- 5 DSR 48 [0 0 0 0] ------- [0:255 5:255 255 5] 2 [0 2] [1 2 3 5->6] [0 0 0 0->0]
r 89.913368578 _4_ RTR --- 4 DSR 32 [0 ffffffff 5 800] ------- [5:255 6:255 32 0] 1 [1 2] [0 2 0 0->0] [0 0 0 0->0]
s 89.913368578 _4_ RTR --- 6 DSR 48 [0 0 0 0] ------- [4:255 5:255 255 5] 2 [0 2] [1 2 3 5->6] [0 0 0 0->0]
r 89.913368941 _1_ RTR --- 4 DSR 32 [0 ffffffff 5 800] ------- [5:255 6:255 32 0] 1 [1 2] [0 2 0 0->0] [0 0 0 0->0]
s 89.913368941 _1_ RTR --- 7 DSR 48 [0 0 0 0] ------- [1:255 5:255 255 5] 2 [0 2] [1 2 3 5->6] [0 0 0 0->0]
r 89.913369041 _2_ RTR --- 4 DSR 32 [0 ffffffff 5 800] ------- [5:255 6:255 32 0] 1 [1 2] [0 2 0 0->0] [0 0 0 0->0]
r 89.919259468 _5_ RTR --- 7 DSR 48 [13a 5 1 800] ------- [1:255 5:255 255 5] 2 [0 2] [1 2 3 5->6] [0 0 0 0->0]
SFESTs 89.919259468 _5_ 3 [5 -> 6] 3(1) to 1 [5 |1 6 ]
s 89.919259468 _5_ RTR --- 3 cbr 552 [13a 6 5 800] ------- [5:1 6:1 32
 
Old 09-10-2007, 07:46 AM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
what have you got so far? This totals up column 8 based on your criteria, however, pls try to do the second one yourself as part of learning
Code:
awk '$3=="_5_" && $4 == "RTR" && $7 == "DSR" { c=c+$8 }END{print c}' "file"
 
Old 09-10-2007, 10:02 PM   #3
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,261

Rep: Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028Reputation: 2028
Personally I'd read the file into a Perl hash, 1st key on node num, then sub-hash by other data items eg, time, pkytype etc.
Then you can easily extract any kind of info combinations you need.
If there is going to be a very large amt of data and you want the flexibility to be able to do other ad-hoc queries later, use eg Perl to put the data in a DB eg MySQL, and then you can use SQL to extract what you need.
 
Old 09-11-2007, 09:19 AM   #4
crabboy
Moderator
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,823

Rep: Reputation: 120Reputation: 120
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate.

continue discussion here:

http://www.linuxquestions.org/questi...d.php?t=582907
 
  


Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
awk/perl script for extract data mruknown1 Linux - Newbie 2 09-11-2007 04:42 AM
How to acess Variable defined in perl script inside an awk call sumin Programming 3 04-26-2007 05:19 AM
perl script, paired data disruptive Programming 2 02-20-2007 07:51 AM
How to extract information from a large data pool with AWK script? underskinned Programming 2 11-23-2006 09:26 PM
How do I zip and attach the output data of a grep | awk | mail shell script? 360 Programming 1 05-08-2002 08:26 AM


All times are GMT -5. The time now is 06:27 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration