I want to split this with every 5 or 50 depend on how much data the file will have. And remove the comma on the end
Source file will have
001,0002,0003,004,005,0006,0007,007A,007B,007C,007E,007F,008A,008C
Need Output from every 5 tab and remove the comma from end of each row
001,0002,0003,004,005
0006,0007,007A,007B,007C
007E,007F,008A,008C
how about:
$ echo '001,0002,0003,004,005,0006,0007,007A,007B,007C,007E,007F,008A,008C' | awk -F, -v b=5 '{for(i=b+1;i<=NF;i=i+b) $i=ORS $i}1' OFS=, | sed 's/,$//'
001,0002,0003,004,005
0006,0007,007A,007B,007C
007E,007F,008A,008C
1 Like
RudiC
3
Try also
tr ',' $'\n' < file | paste -sd',,,,\n'
001,0002,0003,004,005
0006,0007,007A,007B,007C
007E,007F,008A,008C
1 Like
rdrtx1
5
awk 'ORS=(NR%5)? ",":"\n"' RS=, infile
1 Like