Input file
jayesh 30,20,50,60 30:20:40,60:55 A AB,KL,CD SM1,SM2
rahul 10,80,50,90 25:55:60,25 SGF AAAA,BCD,RTY SM3,SM4,SM4
pravin 89,78,40,20 25:30:55,96:25 M J SD10,SD12
sarika 10,20,48 29:50:30,25 T K,L SD20,SD39
I want remove comma's from column 5 and print those words in new line which are present after the comma(Note:- each single cell of the 5th column contains many comma's but i show only few)
Expected output
jayesh 30,20,50,60 30:20:40,60:55 A AB SM1,SM2
jayesh 30,20,50,60 30:20:40,60:55 A KL SM1,SM2
jayesh 30,20,50,60 30:20:40,60:55 A CD SM1,SM2
rahul 10,80,50,90,120 25:55:60,25 SGF AAAA SM3,SM4,SM4
rahul 10,80,50,90,120 25:55:60,25 SGF BCD SM3,SM4,SM4
rahul 10,80,50,90,120 25:55:60,25 SGF RTY SM3,SM4,SM4
pravin 89,78,40,20 25:30:55,96:25 M J SD10,SD12
sarika 10,20,48 29:50:30,25 T K SD20,SD39
sarika 10,20,48 29:50:30,25 T L SD20,SD39
I tried the following using awk but not giving expected results. (to write code i take help from this site How to remove the comma and print the entire row again for the words which are place after the comma)
awk '{
split ($5,w5,",");
for (i in w5)
{ print $1"\t"$2"\t"$3"\t"$4"\t"w5[i]"\t"$6";}}'
@sundeep, when i tried the following command for my input file, 5th and 6th column get mixed with each other.(i just show here total 6 columns but my file have more than 6 columns)
following output is obtained when i open the output file in excel
output
$ awk '{ split ($5,w5,","); for (i in w5) { print $1"\t"$2"\t"$3"\t"$4"\t"w5[i]"\t"$6 } }' ip.txt
jayesh 30,20,50,60 30:20:40,60:55 A "ABSM1,SM2"
jayesh 30,20,50,60 30:20:40,60:55 A KL SM1,SM2
jayesh 30,20,50,60 30:20:40,60:55 A CD" SM1,SM2
rahul 10,80,50,90 25:55:60,25 SGF AAAASM3,SM4,SM4"
rahul 10,80,50,90 25:55:60,25 SGF BCD SM3,SM4,SM4
rahul 10,80,50,90 25:55:60,25 SGF RTY" SM3,SM4,SM4
pravin 89,78,40,20 25:30:55,96:25 M J SD10,SD12
sarika 10,20,48 29:50:30,25 T KSD20,SD39"
sarika 10,20,48 29:50:30,25 T L" SD20,SD39