I have the following csv file with repeated values in column1.
HEADER1,HEADER2,HEADER3,HEADER4
ap3,799,226:::5731,address 1
afk,731,+636:::773:992,address 2
ppd,411,8542,address 6
ap3,799,226,address 1:::address 9
ap3,799,474:::226:::5731,address 1
ppd,411,774:::+8825-22,address 6
For each repeated value in column1, I’d like to make equal the values of column 3 and column 4 in order to keep the value with longest length.
My current output is far away from what I’m looking for. Don’t now how to follow.
$ awk -F',' -v OFS=',' '
FNR==1 { print; next } {
a[$0]=length($3)
}
END {
for (i in a)
print i,a[i]
}' input.csv
HEADER1,HEADER2,HEADER3,HEADER4
,14,731,+636:::773:992,address 2
,16,799,474:::226:::5731,address 1
,10,799,226:::5731,address 1
,33,799,226,address 1:::address 9
,4d,411,8542,address 6
,14,411,774:::+8825-22,address 6
Below the input (to the left) and the output (to the right) I’m looking for.