Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Help with filtering trace file through grep

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 09-21-2010
saqibshah saqibshah is offline
Registered User
 
Join Date: Sep 2010
Last Activity: 21 September 2010, 1:21 PM EDT
Posts: 2
Thanks: 3
Thanked 0 Times in 0 Posts
Help with filtering trace file through grep

Hi,
I am using NS2 and i need to filter a trace file (part of which is shown below):
- 33.91576 2 3 tcp 1040 ------- 1 0.0 4.0 1115 2258
r 33.918907 4 3 ack 40 ------- 1 4.0 0.0 1107 2272
+ 33.918907 3 2 ack 40 ------- 1 4.0 0.0 1107 2272
- 33.918907 3 2 ack 40 ------- 1 4.0 0.0 1107 2272
r 33.9192 2 0 ack 40 ------- 1 4.0 0.0 1103 2264
+ 33.9192 0 2 tcp 1040 ------- 1 0.0 4.0 1123 2275
- 33.9192 0 2 tcp 1040 ------- 1 0.0 4.0 1123 2275
r 33.93256 2 3 tcp 1040 ------- 1 0.0 4.0 1111 2250
+ 33.93256 3 4 tcp 1040 ------- 1 0.0 4.0 1111 2250
- 33.93256 3 4 tcp 1040 ------- 1 0.0 4.0 1111 225
........................

The file needs to be filtered such that column number 3 should only contain "3" and column number 1 should only contain "r" using GREP (or awk).

Any help is greatly appreciated!
Sponsored Links
    #2  
Old Unix and Linux 09-21-2010
bartus11's Unix or Linux Image
bartus11 bartus11 is offline Forum Staff  
Moderator
 
Join Date: Apr 2009
Last Activity: 22 April 2015, 5:35 PM EDT
Posts: 3,733
Thanks: 7
Thanked 1,152 Times in 1,122 Posts

Code:
awk '$1=="r" && $3==3' file

The Following User Says Thank You to bartus11 For This Useful Post:
saqibshah (09-21-2010)
Sponsored Links
    #3  
Old Unix and Linux 09-21-2010
rdcwayx rdcwayx is offline Forum Advisor  
Use nawk in Solaris
 
Join Date: Jun 2006
Last Activity: 22 March 2014, 12:27 PM EDT
Posts: 2,759
Thanks: 44
Thanked 419 Times in 407 Posts
Not really correct, but simple.


Code:
grep "^r.* 3 " file

The Following User Says Thank You to rdcwayx For This Useful Post:
saqibshah (09-21-2010)
    #4  
Old Unix and Linux 09-21-2010
kurumi kurumi is offline
Resident Ruby Wrangler
 
Join Date: Dec 2009
Last Activity: 12 January 2014, 4:32 AM EST
Posts: 601
Thanks: 2
Thanked 83 Times in 78 Posts

Code:
$ ruby -ane 'print if $F[0]+$F[2]=="r3"' file

The Following User Says Thank You to kurumi For This Useful Post:
saqibshah (09-21-2010)
Sponsored Links
    #5  
Old Unix and Linux 09-21-2010
saqibshah saqibshah is offline
Registered User
 
Join Date: Sep 2010
Last Activity: 21 September 2010, 1:21 PM EDT
Posts: 2
Thanks: 3
Thanked 0 Times in 0 Posts
@ everyone...thanks a bunch to all of you for replying so fast!

bartus11`s code worked perfectly so i didnt try the rest but i`m pretty sure they all work fine!! thank again!!
Sponsored Links
    #6  
Old Unix and Linux 09-21-2010
john1212 john1212 is offline
Registered User
 
Join Date: Mar 2010
Last Activity: 25 May 2012, 11:08 AM EDT
Posts: 141
Thanks: 0
Thanked 19 Times in 19 Posts
exactly:

Code:
grep "^r [^ ]* 3 "

Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
grep filtering problem cokedude Shell Programming and Scripting 4 07-08-2010 12:38 AM
Filtering a file JayC89 UNIX for Dummies Questions & Answers 5 06-02-2010 10:28 AM
How to trace file sytem size change? rainbow_bean AIX 1 04-22-2010 06:41 AM
Filtering Log file baanprog UNIX for Dummies Questions & Answers 1 02-09-2009 12:02 PM
Core file without a readable stack trace ciregbu Programming 0 10-02-2002 11:42 AM



All times are GMT -4. The time now is 08:30 AM.