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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk script

Status
Not open for further replies.

maolivar

Technical User
Apr 1, 2008
6
FR
Hi,

I am trying to do script that helps me to filter the following file:
udp/rtp 160 c8 6051 11453920 955869701
udp/rtp 160 c8 12264 1962240 915475809
udp/rtp 160 c8 1461 233760 1811723741
udp/rtp 160 c8 19655 3144800 2138545229
udp/rtp 160 c8 5513 967520 270979107
udp/rtp 160 c8 1800 406080 401604270
udp/rtp 160 c8 6052 11454080 955869701
udp/rtp 160 c8 6053 11454240 955869701

#!/bin/sh
awk '{$6 == "955869701"; {print $0}}'

and the result is:
udp/rtp 160 c8 6051 11453920 955869701
udp/rtp 160 c8 6052 11454080 955869701
udp/rtp 160 c8 6053 11454240 955869701

but I want to do scrit in which it is a variable instead of the chain, in order to obtain the same result, for example:

#!/bin/sh
awk '{ssrc=$6; {if (ssrc == oldssrc) {print $0}}oldssrc=ssrc;}'

but it doesn't work

Please anybody can help me

Thanks

 
...but I want to do scrit in which it is a variable instead of the chain, in order to obtain the same result, for example:

Please clarify your requirements, what needs to be variable instead of a chain to obtain same result?
[3eyes]



----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
Well i want to use a variable instead of the chain

in this example i use a chain " 955869701"

#!/bin/sh
awk '{$6 == "955869701"; {print $0}}'

but imagine that i don't know the chain in order to be able to regroup all the chains that are equal to obtain a result like this

udp/rtp 160 c8 6051 11453920 955869701
udp/rtp 160 c8 6052 11454080 955869701
udp/rtp 160 c8 6053 11454240 955869701

So i try to do it something like
#!/bin/sh
awk '{ssrc=$6; {if (ssrc == oldssrc) {print $0}}oldssrc=ssrc;}'

but i can't obtain the result that i want who is

udp/rtp 160 c8 6051 11453920 955869701
udp/rtp 160 c8 6052 11454080 955869701
udp/rtp 160 c8 6053 11454240 955869701

thanks

 
By "chain", do you mean "string"?

If you don't know the string you are searching for... how will you know which line to get it from? Will it always be the first one in the file? If so, you could do something like this:

Code:
awk '
   NR==1 { ssrc=$6 }
   $6==ssrc
'

Alternatively, if you just want to group all of the matching ssrc fields together, why not just sort the file by the sixth field?

Annihilannic.
 
Hi

Yes i mean "string" and you are rigth Annihilannic. I just want to group all of the matching ssrc fields together

could you tell me how can i use the sort i have an idea for example sort -n, "--numeric-sort compare according to string numerical value".

awk '{{print $0 | "sort -n $6" }} 'file.dat

but i can't obtain the result than i want because it takes the fist row not the sixth

Thanks






 
Why not simply this ?
sort -k6n file.dat

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top