bash - add new line after number of commas -
bash - add new line after number of commas -
i have long line:
kvm1.example.corp,18:18:48,x86_64,16,11,11,0,0,0,0,0,11,0,4.6,99056376,4980736,4980736,5450000000,1,s-75-vm,460000000.,0.385304090422,262144,0,0,3,743,0,2,v-30-vm,450000000.,0.376927914543,1048576,1,0,6,7676,4765,3,r-80-vm,430000000.,0.360175562786,131072,0,0,0,208,0,5,i-2-81-vm,10000000.,0.00837617587873,1048576,1,0,0,0,0,6,r-83-vm,430000000.,0.360175562786,131072,0,0,0,156,0,7,i-3-82-vm,710000000.,0.59470848739,524288,0,0,0,0,0,8,r-85-vm,410000000.,0.343423211028,131072,0,0,0,208,0,11,i-3-84-vm,710000000.,0.59470848739,524288,0,0,0,0,0,12,i-2-79-vm,690000000.,0.577956135633,524288,0,0,2,0,0,13,r-87-vm,420000000.,0.351799386907,131072,0,0,0,156,0,14,i-3-88-vm,730000000.,0.611460839147,524288,0,0,2,0,0
i'm trying output
1,s-75-vm,460000000.,0.385304090422,262144,0,0,3,743,0, 2,v-30-vm,450000000.,0.376927914543,1048576,1,0,6,7676,4765, 3,r-80-vm,430000000.,0.360175562786,131072,0,0,0,208,0, 5,i-2-81-vm,10000000.,0.00837617587873,1048576,1,0,0,0,0, 6,r-83-vm,430000000.,0.360175562786,131072,0,0,0,156,0, 7,i-3-82-vm,710000000.,0.59470848739,524288,0,0,0,0,0, 8,r-85-vm,410000000.,0.343423211028,131072,0,0,0,208,0, 11,i-3-84-vm,710000000.,0.59470848739,524288,0,0,0,0,0, 12,i-2-79-vm,690000000.,0.577956135633,524288,0,0,2,0,0, 13,r-87-vm,420000000.,0.351799386907,131072,0,0,0,156,0, 14,i-3-88-vm,730000000.,0.611460839147,524288,0,0,2,0,0
i'm not sure strategy should take add together new line after 9th comma after removing header?
simpler sed
:
$ sed -r 's/([^,]+,){18}//;s/(([^,]+,){10})/\1\n/g' file 1,s-75-vm,460000000.,0.385304090422,262144,0,0,3,743,0, 2,v-30-vm,450000000.,0.376927914543,1048576,1,0,6,7676,4765, 3,r-80-vm,430000000.,0.360175562786,131072,0,0,0,208,0, 5,i-2-81-vm,10000000.,0.00837617587873,1048576,1,0,0,0,0, 6,r-83-vm,430000000.,0.360175562786,131072,0,0,0,156,0, 7,i-3-82-vm,710000000.,0.59470848739,524288,0,0,0,0,0, 8,r-85-vm,410000000.,0.343423211028,131072,0,0,0,208,0, 11,i-3-84-vm,710000000.,0.59470848739,524288,0,0,0,0,0, 12,i-2-79-vm,690000000.,0.577956135633,524288,0,0,2,0,0, 13,r-87-vm,420000000.,0.351799386907,131072,0,0,0,156,0, 14,i-3-88-vm,730000000.,0.611460839147,524288,0,0,2,0,0
bash scripting sed awk
Comments
Post a Comment