示例代码:
types=("type1" "type2" "type3") # 存储不同记录类型 counts=(10 20 30) # 存储各记录类型的尾数 total_lines=$(wc -l < filename) # 获取文件总行数
for ((i=0; i<${#types[@]}; i++)); do type=${types[$i]} count=${counts[$i]} type_lines=$(grep -c "^${type}|" filename) # 统计该记录类型的行数 if [ $type_lines -ne $count ]; then # 检查行数与尾数是否一致 echo "$type count (${count}) does not match row count (${type_lines})" exit 1 fi done
if [ $(($total_lines-${counts[@]})) -ne 0 ]; then echo "Trailer count mismatch" exit 1 fi
echo "All counts match"