Computing.Net > Forums > Unix > Awk withing an awk?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Awk withing an awk?

Reply to Message Icon

Name: 18dreams
Date: September 2, 2005 at 06:14:29 Pacific
OS: Solaris
CPU/Ram: na
Comment:

I have a formatted outfile. Within one column I have 4 pieces of data that I would like to split in to 4 additional columns. The problem is these are space separated, and the rest of the file is ; delimited. The big problem is that some of the other columns have spaces inside so I can not just do a awk with a single space as the delimiter. Any idea would be greatly appreciated.

The 4 pieces of data in the one column are not always the same length, so a space delimiter is what I need just for the column.

Thanks in advance.

Andy



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: September 2, 2005 at 08:39:42 Pacific
Reply:

I hate to elaborate on the obvious, but can you replace the semi-colon with a space before processing with awk?


0

Response Number 2
Name: 18dreams
Date: September 2, 2005 at 11:03:24 Pacific
Reply:

I can not because there are some fields that have spaces in them and they do not have the same number of spaces in each. One field is simply the name, but you get 1st, mi, Last, and then 1st last and then mr. 1st mi last. etc. There are several columns similar to this.

I think I found a way by mixing in split and length and match. But its very jumbled and its almost working 100%. I was hoping there would be an easy way.

Thanks, do not worry about offending me with something obvious, sometimes those are the ones that get overlooked just because one's looking to hard at it.

thx

Andy


0

Response Number 3
Name: Jim Boothe
Date: September 3, 2005 at 12:59:16 Pacific
Reply:

You can get at those space-delimited components of any given column by using the split command. With your main field delimiter set to semi-colon or whatever, the following code loads column 3 components, delimited by spaces, into an array named c3. Then the print statements print each piece.

split ($3,c3," ")
print "c3a=" c3[1]
print "c3b=" c3[2]
print "c3c=" c3[3]
print "c3d=" c3[4]


0

Response Number 4
Name: Luke Chi
Date: September 7, 2005 at 12:44:34 Pacific
Reply:

awk -F";" ' { gsub(/ [ ]*/, ";", $3); printf("%s;%s;%s;%s;%s\n",$1,$2,$3,$4,$5)} ' input.txt

Assume:
1. 3rd column is the space seperated column
2. There're 5 ; separated columns in each line

Luke Chi


0

Response Number 5
Name: 18dreams
Date: September 28, 2005 at 12:31:07 Pacific
Reply:

Thanks - This is most helpful.

Andy


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Awk withing an awk?

help with an awk script www.computing.net/answers/unix/help-with-an-awk-script/7275.html

SED or AWK www.computing.net/answers/unix/sed-or-awk/3344.html

awk question www.computing.net/answers/unix/awk-question/7115.html