From 9da4a35689d60253efdf60f2a0da6b500fb3da32 Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Mon, 18 Apr 2011 11:15:52 -0400 Subject: helper script --- word-aligner/paste-parallel-files.pl | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 word-aligner/paste-parallel-files.pl 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; + -- cgit v1.2.3