The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 10-26-2005
Registered User
 

Join Date: Aug 2005
Posts: 28
awk and sed

Hi All,

Can any help me in sorting out the below problem

say file abc.txt.Z contains

paa_databasket: { ac=sfs, hkaf=jgh, cellid=113, name=sfs, appid=4862355, camid=24244, add=nfsadkf sfs, dbuid=1145, code=2424 }

paa_databasket: { ac=sfs, hkaf=jgh, cellid=131, name=sfs, appid=4535864, camid=24234, dbuid=5515, add=nfsadkf sfs, code=5524 }

paa_databasket: { ac=sfs, hkaf=jgh, cellid=161, name=sfs, appid=424824, camid=242399, add=nfsadkf sfs, dbuid=5122, code=2424 }

paa_databasket: { ac=sfs, hkaf=jgh, cellid=121, name=sfs, appid=244864, camid=24242, add=nfsadkf sfs, code=2434, dbuid=5675 }

......


Output
===========
cellid=113 appid=4862355 camid=24244 dbuid=1145
cellid=131 appid=4535864 camid=24234 dbuid=5515
cellid=161 appid=4248243 camid=24239 dbuid=5122
cellid=121 appid=2448643 camid=24242 dbuid=5675


Please help me getting the solution for the above problem

thanks
Satish
Reply With Quote
Forum Sponsor
  #2  
Old 10-26-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,003
nawk -f thad.awk abc.txt

thad.awk:
Code:
BEGIN {
  n=split("cellid appid camid dbuid", arrNames, " ")
}

NF {
  for(i=1; i <= n; i++) {
    match($0, arrNames[i] "=[0-9][0-9]*")
    printf("%s%c", substr($0, RSTART, RLENGTH), (i<n) ? " " : "\n")
  }
}
Reply With Quote
  #3  
Old 10-26-2005
Registered User
 

Join Date: Aug 2005
Posts: 28
vgersh99,

Thanks for quick reply but Sorry to say , i didn't get required output for the above mentioned. I am not getting the cellid and appid is not totally is displayed.

Can any one please help me in this....

Thanks
Satish
Reply With Quote
  #4  
Old 10-26-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,003
Quote:
Originally Posted by thaduka
vgersh99,

Thanks for quick reply but Sorry to say , i didn't get required output for the above mentioned. I am not getting the cellid and appid is not totally is displayed.

Can any one please help me in this....

Thanks
Satish
given the sample input in the original post, here's the output I get:
Code:
cellid=113 appid=4862355 camid=24244 dbuid=1145
cellid=131 appid=4535864 camid=24234 dbuid=5515
cellid=161 appid=424824 camid=242399 dbuid=5122
cellid=121 appid=244864 camid=24242 dbuid=5675
Check your input file and repost what you have AND what output you get.
Reply With Quote
  #5  
Old 10-27-2005
Registered User
 

Join Date: Aug 2005
Posts: 28
vgersh99,
The command and script you provided are working fine according to the my input file specified.

In my input file cellid, appid ,campid,dbuid are jumble in the string i.e placed anywhere in the string and appid is a 40characters long. appid is displaying only 2 or 3 char. and the no output.

I think the problem is with input file. I will the correct input file.

Thanks for your help

Thanks
Satish
Reply With Quote
  #6  
Old 10-27-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,003
just out of curiousity..... post a sample of your 'real' input file [if possible]
Reply With Quote
  #7  
Old 10-29-2005
Registered User
 

Join Date: Aug 2005
Posts: 28
vgersh99,

Thanks for your support , I got the required output using the java program.

Thanks
Satish
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 07:23 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0