$ awk '$2=="Hello" {count["Number of "$2" for "substr($1,1,5)]++}END{for(j in count) print j"(time):",count[j]}' gobi1.txt Number of Hello for 10:23(time): 3