Usando awk
awk '! /^detail/ && /.+/ {max=$9} /^detail record/ {count++} END {if (max == count) { print "ok, "max" = "count} else { print "not ok, "max" != "count }}' foo
Ou como script bash
#!/bin/bash
retValue=$(awk '! /^detail/ && /.+/ {max=$9} /^detail record/ {count++} END {if (max != count) { print "1" }}' "$1")
if [[ "$retValue" -eq 1 ]]; then
exit 1
fi
exit 0
Inicie o script com:
<script_name> <data_file>
Exemplo
% cat foo
0001 HD SAP _AP Distribution 20150615 131723 000003 00000003
detail record 1
detail record 2
detail record 3
% awk '! /^detail/ && /.+/ {max=$9} /^detail record/ {count++} END {if (max == count) { print "ok, "max" = "count} else { print "not ok, "max" != "count }}' foo
ok, 00000003 = 3
% cat bar
0001 HD SAP _AP Distribution 20150615 131723 000003 00000004
detail record 1
detail record 2
detail record 3
% awk '! /^detail/ && /.+/ {max=$9} /^detail record/ {count++} END {if (max == count) { print "ok, "max" = "count} else { print "not ok, "max" != "count }}' bar
not ok, 00000004 != 3