diff options
author | Chris Dyer <cdyer@cs.cmu.edu> | 2011-04-18 11:15:52 -0400 |
---|---|---|
committer | Chris Dyer <cdyer@cs.cmu.edu> | 2011-04-18 11:15:52 -0400 |
commit | af0526d5994d641352bdba499d9a74f9e4824b4f (patch) | |
tree | 5b983a9559b56f10d4ec012a38f250adc518e637 /word-aligner/paste-parallel-files.pl | |
parent | b554f07fb59d73a7f3f3ecb62888f8a275946612 (diff) |
helper script
Diffstat (limited to 'word-aligner/paste-parallel-files.pl')
-rwxr-xr-x | word-aligner/paste-parallel-files.pl | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/word-aligner/paste-parallel-files.pl b/word-aligner/paste-parallel-files.pl new file mode 100755 index 00000000..ce53b325 --- /dev/null +++ b/word-aligner/paste-parallel-files.pl @@ -0,0 +1,35 @@ +#!/usr/bin/perl -w +use strict; + +my @fs = (); +for my $file (@ARGV) { + my $fh; + open $fh, "<$file" or die "Can't open $file for reading: $!"; + push @fs, $fh; +} +my $num = scalar @fs; +die "Usage: $0 file1.txt file2.txt [...]\n" unless $num > 1; + +my $first = $fs[0]; +while(<$first>) { + chomp; + my @out = (); + push @out, $_; + for (my $i=1; $i < $num; $i++) { + my $f = $fs[$i]; + my $line = <$f>; + die "Mismatched number of lines!" unless defined $line; + chomp $line; + push @out, $line; + } + print join(' ||| ', @out) . "\n"; +} + +for my $fh (@fs) { + my $x=<$fh>; + die "Mismatched number of lines!" if defined $x; + close $fh; +} + +exit 0; + |