#! /usr/bin/awk -f BEGIN { FS = msg_fs ? msg_fs : "|" OFS = msg_fs ? msg_fs : "|" Kfs = key_fs ? key_fs : ":" } # Modify the record we're interested in $1 == status && $2 == src && ($3 ~ ("^" key_prefix)) { key = $3 val = $4 prev[key] = curr[key] curr[key] = val diff[key] = curr[key] - prev[key] print($1, $2, $3, diff[key]) next } # Let everything else through untouched //