[Solved] Addition of particular numbers in a file using awk or grep


awk '$1 != "Banana" {s+=$(NF-2)} END { print s}' RS= fruites.txt

The key here is the RS= assignment which makes awk treat each section of text delimited by blank lines as a separate record. Note that you may prefer to write RS="" fruites.txt for clarity, but that is not necessary. Be sure not to omit the space after the =, though, as the key is to have a blank string as the value of RS.

— Edit —

Given the comments and the modified question, perhaps you want:

awk '! match($1,"Banana") && match($NF, "found") {
    s += $(NF-2)} END { print s }' RS= fruites.txt

7

solved Addition of particular numbers in a file using awk or grep