awk command to separate a field

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk command to separate a field
# 1  
Old 10-03-2009
awk command to separate a field

I have a log file that I am trying to convert. File contents something like this:

aaaaa bbbbbb cccc dddddd\123 eeeee ffffffff

I am trying to output the fields in a different order and separate field 4 so that the "123" and "dddddd" can be output separately. for example

bbbbbb aaaaa 123 eeeee ffffffff dddddd

The first part of field 3 changes so i cant say print character 1 to 6 of $4 etc.
And I can’t use \ as a second field separator as there are other fields containing \ in it that I want to keep as one field.

I am still new to awk and bash. Can anyone give me any hints?
# 2  
Old 10-03-2009
Maybe ... you may want to

1. separate the sequence of numbers from it's "lettered counterpart"
[house@leonov] echo "aaaaa bbbbbb cccc dddddd\123 eeeee ffffffff" | sed 's/\([0-9]\{3\}\)/ \1/'
aaaaa bbbbbb cccc dddddd\ 123 eeeee ffffffff

2. rearange the fields (based on the now common "space" separator)
[house@leonov] echo "aaaaa bbbbbb cccc dddddd\ 123 eeeee ffffffff" | awk -F ' ' 'BEGIN {OFS=" "} { print $2, $1, $5, $6, $7, $4 }'
bbbbbb aaaaa 123 eeeee ffffffff dddddd\

Last edited by; 10-03-2009 at 05:35 AM.. Reason: Comments added
# 3  
Old 10-03-2009
I was hoping for something a bit more complex then that. The log file I am converting has over 10,000 lines. I would have thought awk was advanced enough to have a feature to split a field??
# 4  
Old 10-03-2009

awk '{split($4,ss,"\\"); print $2,$1,ss[2],$5,$6,ss[1]}' infile

# 5  
Old 10-03-2009
awk -F'[ \t]+|\\' '{print $2,$1,$5,$6,$7,$4}' logfile

Last edited by Scrutinizer; 10-03-2009 at 06:44 AM..
# 6  
Old 10-03-2009
Thanks Scrutinizer and malcomex999. Both solutions worked great.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Awk: output lines with common field to separate files

Hi, A beginner one. my (tab-separated): h1 h2 h3 h4 h5 item1 grpA 2 3 customer1 item2 grpB 4 6 customer1 item3 grpA 5 9 customer1 item4 grpA 0 0 customer2 item5 grpA 9 1 customer2 objective: output a file for each customer ($5) with the item number ($1) only if $2 matches... (2 Replies)
Discussion started by: beca123456
2 Replies

2. Shell Programming and Scripting

awk to create separate files but not include specific field in output

I am trying to use awk to create (in this example) 3 seperate text file from the unique id in $1 in file, if it starts with the pattern aa. The contents of each row is used to populate each text file except for $1 which is not needed. It seems I am close but not quite get there. Thank you :). ... (3 Replies)
Discussion started by: cmccabe
3 Replies

3. Shell Programming and Scripting

awk command to return only field with a number in it

What is an awk command to print only fields with a number in it?? Input file....... S,S,S,S,S,S,S,S,S 001S,S,S,S,S,S,S,S,S 00219S,23S,24S,43S,47S,S,S,S,S 00319S,10S,23S,41S,43S,47S,S,S,S 00423S,41S,43S,46S,47S,S,S,S,S 00510S,23S,24S,43S,46S,S,S,S,S 00610S,23S,43S,46S,47S,S,S,S,S... (2 Replies)
Discussion started by: garethsays
2 Replies

4. Shell Programming and Scripting

awk separate field by letter and ";"

i have a 2 fields in my DB ID25333,1429291340lNormPUC-AP_MEX_UFM-GOL_44;PUC-AP_VEX_UFM-ROL_55;PUCAP_MEX_UFM-DOJ_49; ID55555,1429291340lNormPUC-AP_PPP_UFM-HOL_44;PUC-AF_GEX_UJM-SOL_45;PUCAP_MEX_UFM-DOJ_59;and i need separate like this ID25333,PUC-AP_MEX_UFM-GOL_44; ... (5 Replies)
Discussion started by: Axl_north
5 Replies

5. Shell Programming and Scripting

Pass awk field to a command line executed within awk

Hi, I am trying to pass awk field to a command line executed within awk (need to convert a timestamp into formatted date). All my attempts failed this far. Here's an example. It works fine with timestamp hard-codded into the command echo "1381653229 something" |awk 'BEGIN{cmd="date -d... (4 Replies)
Discussion started by: tuxer
4 Replies

6. Shell Programming and Scripting

handling multiple files using awk command and wants to get separate out file for each

hai all I am new to the world of shell scripting I wanted to extract two columns from multiple files say around 25 files and i wanted to get the separate outfile for each input file tired using the following command to extract two columns from 25 files awk... (2 Replies)
Discussion started by: hema dhevi
2 Replies

7. UNIX for Advanced & Expert Users

Awk command to print the field

894344202808090;11122;040320 075858 166;101;0;0;10u;0;NA;65;221890;2;101973;185059;568674;Y; PRE;0;0;NA;NA;0;NA;0;NA;textmsg;textmsg_snd1;telusmob;TEXTMSG1;0.15000000;126037;2010/03/04 12:58:57gmt;0;70532192; plz tell me any awk command which on the basis of the yellow field which is... (1 Reply)
Discussion started by: madfox
1 Replies

8. Shell Programming and Scripting

Separate date timestamp use awk or sed command ?

Hi, I have logfile like this : Actually the format is date format : yyyymmddHHMMSS and i want the log become this format yyyy-mm-dd HH:MM:SS for example 2009-07-19 11:46:52 Can somebody help me ? Thanks in advance (3 Replies)
Discussion started by: justbow
3 Replies

9. Shell Programming and Scripting

awk field separator or print command

Hello Experts, I am back, with another doubt. I am not sure what it relates to this time - awk or the print command actually. I'll explain the scenario: I have a huge file, and it has some traces(logs). In between those logs, there are statements with some SQL queries. All I want to do is... (4 Replies)
Discussion started by: hkansal
4 Replies

10. Shell Programming and Scripting

separate a line having particular field

hi i have a file containes data like, 20081013-030618.675199 D 17 Change state DATA_RECEIVE->EOD, RC=0 20081013-030618.868358 D 17 Reading data... 20081013-030618.868498 D 18 Received 5 bytes 20081013-030618.868537 U Buffer received: now i need to cut the 4th field i.e 17 and write... (2 Replies)
Discussion started by: Satyak
2 Replies
Login or Register to Ask a Question