The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Hi guys... vinayraj UNIX for Advanced & Expert Users 1 02-07-2008 11:37 PM
Help guys! chuchu Shell Programming and Scripting 2 07-06-2007 06:52 AM
Thanks guys b_manu78 AIX 0 01-03-2006 06:43 AM
Hi again guys M_Hafez UNIX for Dummies Questions & Answers 1 01-16-2005 11:48 AM
i need your guys help souldier UNIX for Advanced & Expert Users 21 03-29-2002 07:26 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-29-2008
zanetti321 zanetti321 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 39
Please Help Me Guys

Dear All

I have a pattern which look like this :

2 20080226_18:02:09.749 ISC-Libya Egypt-Cairo2 111 IAM 2913258040 218927157966 b 61 REL f 143 RLC :COMMA:NCI=10,FCI=6101,CPC=0A,TMR=00,OFI=80,USI: :COMMB:: :RELCAUSE:15:

2 20080226_18:02:11.629 ISC-Libya Egypt-Cairo2 170 IAM 93572641 218923609471 b 62 REL f 167 RLC :COMMA:NCI=10,FCI=6001,CPC=0A,TMR=00,USI: :COMMB:: :RELCAUSE:15:

I want the output file to be like this:

ISC-Libya Egypt-Cairo b 15 ( This for the first pattern)

and for the second Pattern

ISC-Libya Egypt-Cairo b 15 (This for the second pattern)

I mean that i need usually to print $3 ,$4 and the $ which is before REL word by two fields only (When the script find word REL) it awk the field before it by 2 fields

Note that i have lot of these patterns and every group is stored in files which generated every 15 minutes.

Please waiting for any reply from you
  #2 (permalink)  
Old 02-29-2008
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
not sure of what exactly you can assume about your patterns, but...
Code:
echo '2 20080226_18:02:09.749 ISC-Libya Egypt-Cairo2 111 IAM 2913258040 218927157966 b 61 REL f 143 RLC :COMMA:NCI=10,FCI=6101,CPC=0A,TMR=00,OFI=80,USI: :COMMB:: :RELCAUSE:15:' | nawk '{n=split($NF,a, ":");print $3,$4,$9,a[n-1]}'
  #3 (permalink)  
Old 03-01-2008
zanetti321 zanetti321 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 39
Dear Vger

Thanks for your reply but , i think i need to modify the code you sent

2 20080222_19:42:33.407 ISC-Libya Belgium1 8 IAM 38733614670 218214834748 b 2761 ACM b 20101 ANM f 89238 REL b 89541 SUS b 90221 RLC :COMMA: NCI=00,FCI=6100,CPC=0A,TMR=03: :COMMB: BCI=1604,OBI=01: :RELCAUSE:10:

2 20080222_19:43:44.054 ISC-Libya Belgium1 55 IAM 22796236854 218928613546 f 21969 REL b 22440 RLC :COMMA: NCI=10,FCI=6101,CPC=0A,TMR=00,OFI=80,USI: :COMMB:: :RELCAUSE:FF:

As you see in this example the location of REL message in the first pattern differs from location of REL in the second pattern. ( The first REL in $16 while the REL of second pattern is in $11) , so the key is word REL as soon as the code finds it prints the field before it by two fields.

So what i need is to print only $3 ,$4 as there position don't change and also i want to print the field which is before REL by two fields and also i want to print the last field in the pattern so the output for the two patterns will be like this:

ISC-Libya Belgium1 f 10

ISC-Libya Belgium1 f FF

Thanks for your care and please supply me with your reply.

Regards
  #4 (permalink)  
Old 03-01-2008
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
nawk -f zan.awk myFile.txt

zan.awk:
Code:
{
   foo="<unknown>"
   for(i=1; i<=NF; i++)
      if (i > 2 && $i == "REL") {
         foo=$(i-2)
         break
      }
   n=split($NF,a, ":")
   print $3,$4,foo,a[n-1]
}

Last edited by vgersh99; 03-01-2008 at 12:48 PM.. Reason: added 'i>2'
  #5 (permalink)  
Old 03-01-2008
zanetti321 zanetti321 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 39
Last question

Dear VGER

thanks for your reply i think this script will work but i have a question from where should i write the script

Starting after code: ?or i should write also nawk -f zan.awk myFile.txt

zan.awk:

Can the script format be:

Cat filename.* ( * refers to date) and then writing the script

The file names are CDR.1,CDR.2,CDR.3 and every file contains group of patterns i sent you so the script should process all these files once and getting me the output

Thanks is advance and sorry for lot of questions
  #6 (permalink)  
Old 03-01-2008
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
create a text file 'zan.awk' as outlined in the post.
from a shell prompt invoke the posted command:
Code:
nawk -f zan.awk CDR.1 CDR.2 CDR.3
  #7 (permalink)  
Old 03-01-2008
zanetti321 zanetti321 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 39
Can anyone help

i have another pattern which look like this :

2 20080222_19:42:33.407 ISC-Libya Belgium1 8 IAM 38733614670 218214834748 b 2761 ACM b 20101 ANM f 89238 REL b 89541 SUS b 90221 RLC :COMMA: NCI=00,FCI=6100,CPC=0A,TMR=03: :COMMB: BCI=1604,OBI=01: :RELCAUSE:10:

For this pattern i want to subtract the field before ANM word from the field before ACM word and if the result is less than 1000 i should print the whole pattern and sure skip the patterns which don't achieve this condition and at the end i like to redirect the output to another file.

Note also the position of ACM and ANM is not fixed for the all the patterns.

Can you tell me if the below code is right:

{
foo= "<unknown>"
too= "<unknown>"
result="<unknown>"

for (i =1 ; i<= NF; i++)
if (i>2 && $i == "ANM") {
foo = $(i-1)
break
}

for (k=1 ;k<=NF;i++)
if(k>2 && $k == "ACM"{
too =$(k-1)
break
}
result == too - foo
if (result <=1000){
print $0
}
( is $0 refer to printing the whole line where the condition is achieved)

then after printing the output i want to redirect it to a separate file.

I am sure that the code need modification so please update it if it need modification to try it on my server.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




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


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0