#!/usr/bin/perl -w use strict; # Run a program, captures its output, and return all the lines sub Run($) { my ($prog) = @_; my @lines = `$prog`; if( $? != 0 ) { die "$prog failed: $?\n"; } unless( scalar @lines ) { die "$prog produced no output\n"; } return @lines; } die "$0 \n" unless $#ARGV == 1; my @cat1 = Run($ARGV[0]); my @cat2 = Run($ARGV[1]); # First part of both output must match if( (scalar @cat1) >= (scalar @cat2) ) { die "Unexpected output sizes\n"; } for(my $i = 0; $i <= $#cat1; $i++) { if( $cat1[$i] ne $cat2[$i] ) { die "Mismatched on line $i\n" . "a: $cat1[$i]" . "b: $cat2[$i]" . "\n"; } } # Extra part of longer file must be repeating the last line for(my $i = $#cat1; $i <= $#cat2; $i++) { if( $cat1[$#cat1] ne $cat2[$i] ) { die "Unexpected line $i\n"; } } # All good exit 0;