Hi ,
I am having a problem with my awk oneliner , which for some reason leaves the first two records
Input File
$ cat file1
A1:B1:C1:NoLimit
M1:M2:M3:Limit
A2:B2:C2,C3,C4,C5
A3:B3:C3,C4,C5,C6,C7
Desired output
A1,B1,C1,NoLimit
M1,M2,M3,Limit
A2,B2,C2
,,,C3
,,,C4
,,,C5
A3,B3,C3
,,,C4
,,,C5
,,,C6
,,,C7
I am using the below oneliner to achieve it partially but i dont get why the first two records OFS does not change to comma ,
nawk 'BEGIN{FS=":";OFS=","}{gsub(",","\n,,,",$NF);print}' file1
This gives me an output
A1:B1:C1:NoLimit
M1:M2:M3:Limit
A2,B2,C2
,,,C3
,,,C4
,,,C5
A3,B3,C3
,,,C4
,,,C5
,,,C6
,,,C7
Can someone please help me understand the problem and correct the code