With the data in a file called books,
the numbers for each book can be added and printed them as follows:
$ awk '{n[$1]+=$4} END{for (b in n) {print b,n[b]}}' books
AF116642 3
AF116643 14
AF116644 10
In the above code, n
is an associative array. The keys are the book names. Every time that we encounter a line, the number in the fourth column, denoted $4
, is added to the total for its book, n[$1]
where $1
is the name of the book in the first column.