Unix/Linux Forum: Shell script awk parsing stream log - Unix/Linux Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Shell script awk parsing stream log using awk Rate Topic: -----

#1 User is offline   justbow Icon

  • Newbie (User Level: 0/10)
  • Group: Members
  • Posts: 7
  • Joined: 19-January 09

Post icon  Posted 19 January 2009 - 12:37 PM

Hi,

I have log in here
There are any line that print
3GPP-IMSI : String Value = 528111500090773
Calling-Station-Id : String Value = 6738804956

Then I will parse log become ( only takes IMSI and MSISDN number )

3GPP-IMSI,Calling-Station-Id
528111500090773,6738804956
.
.
.
.
end

Can anybody help me?

I've try using awk and doesn't work

here my script

Quote

awk '
/\Dictionary\ /{f=1}
/\3GPP-IMSI\ /{imsi=$2}
f && /\Calling-Station-Id\ /{msisdn=$2}


f && /Accounting /{
s= imsi "," msisdn
print s
f=0
}' SBR_FE2_grep.log

0

#2 User is offline   eggi Icon

  • User Level: 6/10
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 311
  • Joined: 25-November 07
  • Location:Grayslake, IL USA

Posted 21 January 2009 - 03:01 AM

Hey there,

I'm somewhat confused. Why does your awk statement begin with a pattern match for the word "Dictionary." Is something left out of the example?

Thanks,

Mike
The greatest viral marketing idea of all time, get your copy of this Free Report now!
----
Linux Tips, Trick and Advice -- The Linux and Unix Menagerie
0

#3 User is offline   justbow Icon

  • Newbie (User Level: 0/10)
  • Group: Members
  • Posts: 7
  • Joined: 19-January 09

Posted 22 January 2009 - 11:43 PM

i try this

Quote

awk '
/\Accounting\ Request/{print s;f=1}
f && /3GPP-IMSI /{print $8}
f && /Calling-Station-Id /{print $8}
{s=$8 " " $9}' SBR_FE2_grep.log


then result become

528111500111614
6738790448

528111500075211
6738863638

528111500068173
6738769831

528111410001944
6738718661

528111500058725
6738791509

528111500090773
6738804956

528111500072850
6738885717

528111400012622
6738980388


...

i wanna result become this
528111500111614,6738790448
528111500075211,6738863638
528111500068173,6738769831
528111410001944,6738718661
528111500058725,6738791509
528111500050141,6738899302
528111500072850,6738885717
528111400012622,6738980388
528111510008438,6738893884
528111500084284,6738999866
528111500077061,6738887170
528111500121956,6738970043
528111500121956,6738970043
528111500121956,6738970043


can u help me
0

#4 User is offline   eggi Icon

  • User Level: 6/10
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 311
  • Joined: 25-November 07
  • Location:Grayslake, IL USA

Posted 23 January 2009 - 02:38 AM

Hey again,

I don't see "Accounting Request" in the original text you're trying to parse?

, Mike
The greatest viral marketing idea of all time, get your copy of this Free Report now!
----
Linux Tips, Trick and Advice -- The Linux and Unix Menagerie
0

#5 User is offline   justbow Icon

  • Newbie (User Level: 0/10)
  • Group: Members
  • Posts: 7
  • Joined: 19-January 09

Posted 23 January 2009 - 12:20 PM

hi Mike my log in here
0

#6 User is offline   eggi Icon

  • User Level: 6/10
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 311
  • Joined: 25-November 07
  • Location:Grayslake, IL USA

Posted 24 January 2009 - 02:10 AM

Thanks, man,

Here's an easier way, since you've done all of the work already. It looks like you just don't want the two parts of the line to both have carriage returns, like

aaaa
bbbb

you want

aaaabbbb

You can do that by chaning the first

{print $8}

to

{printf("%s", $8)}

and perhaps (if that causes issues) change the second one to

{printf("%s\n", $8)}

Basically, all you need to do is clip the newline on the first "print $8" in each loop. This might be slightly more complex if there are hard returns in your file, but you can strip them from the first one pretty easily.

Best wishes,

Mike
The greatest viral marketing idea of all time, get your copy of this Free Report now!
----
Linux Tips, Trick and Advice -- The Linux and Unix Menagerie
0

#7 User is offline   justbow Icon

  • Newbie (User Level: 0/10)
  • Group: Members
  • Posts: 7
  • Joined: 19-January 09

Posted 24 January 2009 - 02:55 PM

Hi Mike

do u mean like this :

Quote

awk '
/\Accounting\ Request/{print s;f=1}
f && /3GPP-IMSI /{printf("%s\n", $8)}
f && /Calling-Station-Id /{printf("%s\n",$8)}
{s=$8}' SBR_FE2_grep.log


i've try but the result still can't print new line..
here is the result :

Quote

528111500111614
6738790448

528111500075211
6738863638

528111500068173
6738769831

528111410001944
6738718661

528111500058725
6738791509

528111500090773
6738804956

528111500072850
6738885717

528111400012622
6738980388

528111510008438
6738893884

528111500084284
6738999866

528111500077061
6738887170

528111500121956
6738970043


is there any way
may be the other script
0

#8 User is offline   eggi Icon

  • User Level: 6/10
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 311
  • Joined: 25-November 07
  • Location:Grayslake, IL USA

Posted 25 January 2009 - 02:24 AM

Hey There,

Almost, but since you want the second variable to tag onto the end of the first before the newline, change this line:

Quote

f && /3GPP-IMSI /{printf("%s\n", $8)}


to

Quote

f && /3GPP-IMSI /{printf("%s", $8)}


removing the newline and the two parts should print together, since only your second printf statement has a newline.

Best wishes,

Mike
The greatest viral marketing idea of all time, get your copy of this Free Report now!
----
Linux Tips, Trick and Advice -- The Linux and Unix Menagerie
0

#9 User is offline   justbow Icon

  • Newbie (User Level: 0/10)
  • Group: Members
  • Posts: 7
  • Joined: 19-January 09

Posted 26 January 2009 - 03:00 AM

Hello Mike,

Hihi, maybe we just do a little bit trick,

Quote

awk '
/\Accounting\ Request/{print s;f=1}
f && /3GPP-IMSI /{printf("%s", $8)}
f && /Calling-Station-Id /{printf("%s", ","$8)}' SBR_FE2_grep.log


then the result become :

Quote

528111500111614,6738790448
528111500075211,6738863638
528111500068173,6738769831
528111410001944,6738718661
528111500058725,6738791509
528111500090773,6738804956
528111500072850,6738885717
528111400012622,6738980388
528111510008438,6738893884
528111500084284,6738999866
528111500077061,6738887170
528111500121956,6738970043



Thanks Mike..
0

#10 User is offline   eggi Icon

  • User Level: 6/10
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 311
  • Joined: 25-November 07
  • Location:Grayslake, IL USA

Posted 26 January 2009 - 04:34 AM

Excellent :)

Glad to help and glad you got that all figured out :)

Best wishes,

Mike
The greatest viral marketing idea of all time, get your copy of this Free Report now!
----
Linux Tips, Trick and Advice -- The Linux and Unix Menagerie
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Cambridge Plus :: Cambridgeshire Steam Rally :: Touch Sensor Chip :: Classic Motorcycle Piston Rings
Unix Man Pages / Linux Man Pages :: HiFi Forum :: A14 Comments :: UNIX/Linux Forum Archives