#!/bin/awk -f /^X-Reject: [(]-?[0-9]+[)] / { # Extract the score from this reject line item_score = substr($2, 2, length($2) - 2) score += item_score } NF < 1 { # End of mail headers, output the score print score + 0 exit }