Split and print
I have a file with data such as:
X Y Z 4 1,3,5,7, 4,6,8,10,
A B C 3 2,3,4, 5,9,11,
E F G 5 1,2,3,4,5, 8,9,10,11,12,
Columns 1, 2 and 3 are descriptions. Column 4 tells how many numbers are in columns 5 and 6
What I'd like to do is split column 5 and column 6 by the "," and then print out a line with columns 1, 2, 3, 4, and the 1st number from column 5 and column 6, then print out a line with columns 1, 2, 3, 4,and the 2nd number in cols 5 and 6 ... until all the numbers in 5 and 6 are printed.
X Y Z 4 1 4
X Y Z 4 3 6
X Y Z 4 5 8
X Y Z 4 7 10
A B C 3 2 5
A B C 3 3 9
A B C 3 4 11
E F G 5 1 8
E F G 5 2 9
E F G 5 3 10
E F G 5 4 11
E F G 5 5 12
I was trying something like:
awk '{
split($5,a,",");
split($6,b",");
for (i=1; i<= $4; i++)
print $1,$2,$3, a[i], b[i]
}’
infile > outfile &
This isn't working
Thank you so much.
edit:
%$#%# I just messed up the syntax it works if I can use the commas correctly
split($5,a, ",");
split($6,b, ",");
Sorry