I have a csv file
D,FNAME,MNAME,LNAME,GENDER,DOB,snapshot,PID.1,PID2,FNAME.1,MNAME.1,LNAME.1,FNAME2,MNAME2,LNAME2
,,,,,,201211.0,2,6,6,J,J,D,,
,,,,,,201211.0,3,4,6,H,H,M,,
,,,,,,201211.0,6,7,8,d,d,d,,
,,,,,,201211.0,0,2,5,6,7,8,,
,,,,,,201211.0,,,,,,,,
,,,,,,201211.0,,,,,,,,
What I want to do is use information in columns PID.1, FNAME.1,MNAME.1,LNAME.1 to fill Columns D,FNAME,MNAME,LNAME if there are null value and then output all columns to a new csv file. So my expected output is
D,FNAME,MNAME,LNAME,GENDER,DOB,snapshot,PID.1,PID2,FNAME.1,MNAME.1,LNAME.1,FNAME2,MNAME2,LNAME2
2,6,J,J,,,201211.0,2,6,6,J,J,D,,
3,6,H,H,,,201211.0,3,4,6,H,H,M,,
6,8,d,d,,,201211.0,6,7,8,d,d,d,,
0,5,6,7,,,201211.0,0,2,5,6,7,8,,
,,,,,,201211.0,,,,,,,,
,,,,,,201211.0,,,,,,,,
I tried to use awk to do it my self.
Here is my code.
awk -F, '{if ($1=="" && $8!="")$1=$8;print $0}' test4.csv | awk -F, '{if ($2=="" && $10!="")$2=$10;print $0}' | awk -F, '{if ($3=="" && $11!="")$3=$11;print $0}' | awk -F, '{if ($4=="" && $12!="")$4=$12;print $0}'
The output was
D,FNAME,MNAME,LNAME,GENDER,DOB,snapshot,PID.1,PID2,FNAME.1,MNAME.1,LNAME.1,FNAME2,MNAME2,LNAME2
2 201211.0 2 6 6 J J D
3 201211.0 3 4 6 H H M
6 201211.0 6 7 8 d d d
0 201211.0 0 2 5 6 7 8
,,,,,,201211.0,,,,,,,,
,,,,,,201211.0,,,,,,,,
So I did not make it. Is there anyone who can help me? Thank you.