awk and get a part of field ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk and get a part of field ?
# 1  
Old 06-26-2012
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.
# 2  
Old 06-26-2012
How about:
Code:
awk -F'[/|]' '{ print $7","$10"/"$11","$14}' infile

or:
Code:
awk -F'[/|]' '{gsub(/.*directory_/,"");print $1","$(NF-6)"/"$(NF-5)","$(NF-2)}' infile

# 3  
Old 06-27-2012
Thanks, it works.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to adjust coordinates in field based on sequential numbers in another field

I am trying to output a tab-delimited result that uses the data from a tab-delimited file to combine and subtract specific lines. If $4 matches in each line then the first matching sequential $6 value is added to $2, unless the value is 1, then the original $2 is used (like in the case of line... (3 Replies)
Discussion started by: cmccabe
3 Replies

2. Shell Programming and Scripting

Find and delete part of field with awk or sed

I've got a file that looks like this (the whitespace between commas is intentional): 123456789,12,JOHN H DOE ,DOE/JOHN H ,,,DOE/JOHN H ,,,,,123 FAKE STREET ,SPRINGFIELD,XX, I want to strip just the first name out of the third field so it reads "JOHN,". So far I... (6 Replies)
Discussion started by: Scottie1954
6 Replies

3. Shell Programming and Scripting

[Solved] sort on numeric part of field

I have ran into a heavy case of PEBCAK*) and could need some advice on what i do wrong: OS is Linux (kernel 2.6.35), sort --version reports "8.5" from 2010, shell is ksh. Originally i had a file with with the following structure: hdisk1 yyy hdisk2 yyy hdisk3 yyy hdisk4 yyy hdisk5 yyy... (2 Replies)
Discussion started by: bakunin
2 Replies

4. Shell Programming and Scripting

awk to split one field and print the last two fields within the split part.

Hello; I have a file consists of 4 columns separated by tab. The problem is the third fields. Some of the them are very long but can be split by the vertical bar "|". Also some of them do not contain the string "UniProt", but I could ignore it at this moment, and sort the file afterwards. Here is... (5 Replies)
Discussion started by: yifangt
5 Replies

5. Shell Programming and Scripting

AWK: Pattern match between 2 files, then compare a field in file1 as > or < field in file2

First, thanks for the help in previous posts... couldn't have gotten where I am now without it! So here is what I have, I use AWK to match $1 and $2 as 1 string in file1 to $1 and $2 as 1 string in file2. Now I'm wondering if I can extend this AWK command to incorporate the following: If $1... (4 Replies)
Discussion started by: right_coaster
4 Replies

6. Shell Programming and Scripting

Remove part of a string from second field

I have a file in below format (pipe delimited): 1234__abc|John__abc|xyz 3345__abc|Kate__abc|xyz 55344|Linda__abc|xyz 33434|Murray|xyz I want to remove any occurence of "__abc" in the second field of this file. I did some research and found a way to replace the entire second field with... (5 Replies)
Discussion started by: rajv
5 Replies

7. Shell Programming and Scripting

awk, comma as field separator and text inside double quotes as a field.

Hi, all I need to get fields in a line that are separated by commas, some of the fields are enclosed with double quotes, and they are supposed to be treated as a single field even if there are commas inside the quotes. sample input: for this line, 5 fields are supposed to be extracted, they... (8 Replies)
Discussion started by: kevintse
8 Replies

8. Shell Programming and Scripting

How to select or make reference to, part of a field

For a field format such as AAL1001_MD82, how do I select(and use in if statement) only the last four elements( in this case MD82) or the first three elements (in this case AAL)? For instance, how do I do the following - if first three elements of $x == yyy, then ... (5 Replies)
Discussion started by: akshaykr2
5 Replies

9. Shell Programming and Scripting

Extract Part of string from 3rd field $3 using AWK

I'm executing "wc -lc" command in a c shell script to get record count and byte counts and writing them to a file. I get the result with the full pathname of the file. But I do not want the path name to be printed in the output file. I heard that using Awk we can get this but I don't have any... (4 Replies)
Discussion started by: stakuri
4 Replies

10. Shell Programming and Scripting

Moving Part of a field to another field using AWK

Hi there, I have a comma seperated file with nine fields the fields are rerate: "numberTX",field2,field3,field4,field5..... I want to do this to the file reate: "field5TX",field2,field3,field4,field5 I know I can do this using AWK, but the thing giving me fits is that I... (5 Replies)
Discussion started by: rjsha1
5 Replies
Login or Register to Ask a Question