Skip to content
Advertisement

Awk script to sum multiple column if value in column1 is duplicate

Need your help to resolve the below query. I want to sum up the values for column3,column5,column6, column7,column9,column10 if value in column1 is duplicate. Also need to make duplicate rows as single row in output file and also need to put the value of column1 in column 8 in output file

input file

JavaScript

output file

JavaScript

Tried below code, but it is not working and also no clue how to complete the code to get correct output

JavaScript

Advertisement

Answer

JavaScript

The above outputs the lines in random order, if you want them output in the same order as the key values were read in, it’s just a couple more lines of code:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement