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

parsing a file in unix

Status
Not open for further replies.

dvknn

IS-IT--Management
Mar 11, 2003
94
0
0
US
Hi,

I have file which has lines like this:

2004.07.26 17:58:41 [ExecuteThread: '7' for queue: 'default'] awls3.sac.fedex.com [5] weblogic PASSPORTMESSAGE.PARSE Parsing message: 0,"627"1,"00001786"4000,"ggg00h0cad"4111,"leaflet"4145,"2"4123,"1"4124,"25"99,""

2004.07.26 17:59:04 [ExecuteThread: '3' for queue: 'default'] awls3.sac.fedex.com [5] weblogic PASSPORTMESSAGE.PARSE Parsing message: 0,"627"1,"00002084"4000,"ggg00h0cad"4111,"documents"4145,"2"4123,"1"4124,"25"99,""

I would LOVE to see the file in this format:
2004.07.26 0,"627"4000,"ggg00h0cad"4111,"leaflet"4145,"2"
2004.07.26 0,"627"4000,"ggg00h0cad"4111,"documents"4145,"2"

Can ANYBODY help me Please?

Thanks,
 
man awk

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Is all the data on one line

2004.......99,""

If so you could do

#----------------------------------------------------
sed "s/,/ /g" filename > filename.new

sed "/^$/d" filename.new > filename

cat filename | awk '{print $1,$14,","$15.........}' > new.filename
#----------------------------------------------------


1. Replace , with a space
2. Deletes blank lines
3. list the file & prints 1 14 15 fields, you'll need to play with this to pick your fields, you may also have to change " to space and then re-insert then in your awk, like I did the the "," in the print print of the line.


Hope this helps, If you need any more help just ask.

Mike

"A foolproof method for sculpting an elephant: first, get a huge block of marble, then you chip away everything that doesn't look like an elephant.
 
Thanks Mike.

When I run

cat filename | awk '{print $1,$8,$14,","$15,$17,$18,$19}' > filename.out

2004.07.26 18:52:25 [ExecuteThread: '3' for queue: 'default'] awls3.sac.fedex.com [5] weblogic PASSPORTMESSAGE.PARSE Parsing message: 0,"627"1,"00013328"4000,"g00g038f26"4111,"scientific equipment"4145,"1"4123,"1"4124,"25"99,""
2004.07.26 18:52:26 [ExecuteThread: '3' for queue: 'default'] awls3.sac.fedex.com [5] weblogic PASSPORTMESSAGE.PARSE Parsing message: 0,"627"1,"00013328"4000,"g00g038f26"4111,"scientific equipment machinery"4145,"2"4123,"1"4124,"25"99,""

I am not comfortable working with awk per se. I am more of a VB, Java and XML developer who know a bit about scripting.

I have one more question. Can I say something like, 'give me an output till the string 4145,"1" (4145 is always followed by "number". In place of 1, I may have any number)

2004.07.26 0,"627"4000,"g00g038f26"4111,"scientific equipment"4145,"1"
2004.07.26 0,"627"4000,"g00g038f26"4111,"scientific equipment machinery"4145,"2"


Thanks a bunch.
 
Yes it is possible,

But it may be worth taking a look in the awk forum where I'm sure you'll find lots of examples or look at perl to parse the file.

look at using -F to introduce a field seperator into the awk statement.



Mike

"A foolproof method for sculpting an elephant: first, get a huge block of marble, then you chip away everything that doesn't look like an elephant.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top