#!/bin/sh for i do awk ' function check(line, pat) { if (line ~ pat) return 1; print line; return 0; } BEGIN { ok = 1; } { if (NR > 5 || !ok) { print $0; next; } if (NR == 1) { ok = check($0, ".*<<<<.*") next; } if (NR == 2) { ok = check($0, ".*NetBSD:.*") next; } if (NR == 3) { ok = check($0, ".*====.*") next; } if (NR == 4) { ok = check($0, ".*NetBSD:.*") print $0; next; } if (NR == 5) { ok = check($0, ".*>>>>.*") next; } }' $i > tmp$$ && mv tmp$$ $i done