|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
awk and get a part of field ?
I have a list of log.txt, thisis a flatfile separate by a pipe | Code:
2012/06/23 18:58:15 | 4:sabercats pid=020272 opened Boards 0, 1, 2, 3 for /home/directory_germany/germany/location/qt/NET12/full_111_ddr5_soq523_2X_FV_4BD_PD3_0.qt/dbFiles/germany.proto |berlin|test1|test2 2012/06/25 17:40:56 | 168:sabercats pid=004319 opened Boards 0,2 for /home/directory_england/england/location/qt/NET06/full_2X_FV_1BD_PD3_.qt/dbFiles/england.proto |cambridge|test1|test2 2012/06/26 15:14:02 | 146:sabercats pid=014780 opened Boards 0, 1, 2, 3 for /home/directory_spain/spain/location/qt/NET08/full_111_sddr3_soq523_2X_FV_4BD_PD3_2.qt/dbFiles/spain.proto |madrix|test3|test4 2012/06/26 10:47:35 | 44:sabercats pid=019276 opened Boards 0, 1, 2, 3 for /home/directory_spain/spain/location/qt/NET08/full_111_sddr3_soq523_2X_FV_4BD_PD3_1.qt/dbFiles/spain.proto |barcelona|test5|test6 How do we run awk and get a new file with location.txt and separate field by a comma or pipe and the results should be: Code:
germany,NET12/full_111_ddr5_soq523_2X_FV_4BD_PD3_0.qt,berlin england,NET06/full_2X_FV_1BD_PD3_.qt,cambridge spain,NET08/full_111_sddr3_soq523_2X_FV_4BD_PD3_2.qt,madrix spain,NET08/full_111_sddr3_soq523_2X_FV_4BD_PD3_1.qt,barcelona Thanks for replying. |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
How about: Code:
awk -F'[/|]' '{ print $7","$10"/"$11","$14}' infileor: Code:
awk -F'[/|]' '{gsub(/.*directory_/,"");print $1","$(NF-6)"/"$(NF-5)","$(NF-2)}' infile |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Thanks, it works.
|
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| awk to split one field and print the last two fields within the split part. | yifangt | Shell Programming and Scripting | 5 | 04-17-2012 04:41 AM |
| Remove part of a string from second field | rajv | Shell Programming and Scripting | 5 | 09-20-2011 09:15 AM |
| How to select or make reference to, part of a field | akshaykr2 | Shell Programming and Scripting | 5 | 07-01-2009 10:09 AM |
| Extract Part of string from 3rd field $3 using AWK | stakuri | Shell Programming and Scripting | 4 | 10-10-2007 12:28 PM |
| Moving Part of a field to another field using AWK | rjsha1 | Shell Programming and Scripting | 5 | 08-04-2006 05:39 AM |
|
|