Hi All,
I am trying to split a record into multiple records based on a value.
Input.txt
"A",1,0,10
"B",2,0,10,15,20
"C",3,11,14,16,19,21,23
"D",1,0,5
My desired output is:
"A",1,0,10
"B",2,0,10
"B",2,15,20
"C",3,11,14
"C",3,16,19
"C",3,21,23
"D",1,0,5
I tried this code could you please assist me:
awk 'BEGIN {RS=ORS=","}
(NR > 1) && ($2>1) { ORS="\n"; print ""; ORS="," }
1
' Input.txt
Thanks in advacne.
---------- Post updated at 04:02 PM ---------- Previous update was at 12:55 PM ----------
I got some solution, need some modification:
$ awk -F',' '{for (i =2; ++i <= NF;) print $1 "," $2 "," $i}' H_Input.txt
For the above command I am getting below output:
"A",1,0
"A",1,10
"B",2,0
"B",2,10
"B",2,15
"B",2,20
"C",3,11
"C",3,14
"C",3,16
"C",3,19
"C",3,21
"C",3,23
"D",1,0
"D",1,5
but desired output is:
"A",1,0,10
"B",2,0,10
"B",2,15,20
"C",3,11,14
"C",3,16,19
"C",3,21,23
"D",1,0,5