Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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

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

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]

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 lineLuke Chi

![]() |
![]() |
![]() |

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