|
| Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free! |
Awk withing an awk?
|
Original Message
|
Name: 18dreams
Date: September 2, 2005 at 06:14:29 Pacific
Subject: Awk withing an awk?OS: SolarisCPU/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
Report Offensive Message For Removal
|
|
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?
Report Offensive Follow Up For Removal
|
|
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
Report Offensive Follow Up For Removal
|
|
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]
Report Offensive Follow Up For Removal
|
|
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
Report Offensive Follow Up For Removal
|

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
Results for: Awk withing an awk?
help with an awk script Summary: How do I fix this awk. I would like to have the following occur. I want to process in order of occurance first if statement, second if that is remarked out and then else. I can run either the first o... www.computing.net/answers/unix/help-with-an-awk-script/7275.html
SED or AWK Summary: Here is an awk solution, although it can be done easily with sed also. If the second line ends with an equal-sign followed by one or more spaces, it will not be seen as ending with an equal-sign, but... www.computing.net/answers/unix/sed-or-awk/3344.html
awk question Summary: No, the only way I can see to do it in awk with an unsorted file is saving the data in a 2-dimensional array and printing it out at the end. Makefile sure your file is sorted by field one before you... www.computing.net/answers/unix/awk-question/7115.html
|
|

|