I have a big csv file like this example:
9,AGCTGTCCTCTT,SCPL
9,AGCTGTCATTTTGTTTCG,SCHFVS
9,AGCTGTAATTGTCGTAAGAGGTCTGCTTATTGTTATTTGTGTGGCCCG,SCNCRKRSAYCYLCGP
9,AGCTGTCCTCTT,SCPL
9,AGCTGTAGTCATTTGGGTTTTATTTGTTTTCATGGCATTGTGGCCCG,
1 - In some lines the 3rd column is empty , so they should be removed
2 - Some lines have similar characters in the 3rd column. If that is the case, I want to sum up the values in the 1st column and put it in the 4th column. If the characters in the 3rd column is not repeated in other rows, I want to copy the value of the 1st column into the 4th column.
Expected output:
9,AGCTGTCCTCTT,SCPL,18
9,AGCTGTCATTTTGTTTCG,SCHFVS,9
9,AGCTGTAATTGTCGTAAGAGGTCTGCTTATTGTTATTTGTGTGGCCCG,SCNCRKRSAYCYLCGP,9
To do so, I made the following code in awk but it does not return the expected output.
awk -F "," '{ if(($3 == '') && ({t=3;for(i=2;i<NF;i++){t+=$i==$(i+1)}}t==NF)) { print } }' infile.csv > outfile.csv
Do you know how I can change the code to get the expected output?