Splitting a comma separated string into individual rows
Today I got the problem that I my data looks like this:
col1 | col2 | col3 |
A | B | a,b,c |
C | D | c,d,e |
but I wanted to have something like that:
col1 | col2 | col3 |
A | B | a |
A | B | b |
A | B | c |
C | D | c |
C | D | d |
C | D | e |
Using awk was the fastest solution for me:
cat file.in | awk -F "\t" '{n=split($3,s,";"); for(i=1;i<=n;i++) {$3=s[i];print}}' >> file.out