summaryrefslogtreecommitdiff
path: root/extools/merge_lines.pl
diff options
context:
space:
mode:
authorredpony <redpony@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-06-22 05:12:27 +0000
committerredpony <redpony@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-06-22 05:12:27 +0000
commit0172721855098ca02b207231a654dffa5e4eb1c9 (patch)
tree8069c3a62e2d72bd64a2cdeee9724b2679c8a56b /extools/merge_lines.pl
parent37728b8be4d0b3df9da81fdda2198ff55b4b2d91 (diff)
initial checkin
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@2 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'extools/merge_lines.pl')
-rwxr-xr-xextools/merge_lines.pl43
1 files changed, 43 insertions, 0 deletions
diff --git a/extools/merge_lines.pl b/extools/merge_lines.pl
new file mode 100755
index 00000000..8711e4ce
--- /dev/null
+++ b/extools/merge_lines.pl
@@ -0,0 +1,43 @@
+#!/usr/bin/perl -w
+use strict;
+
+if (scalar @ARGV < 2) {
+ die "Usage: $0 file1.txt file2.txt ...\n\n Concatenate the nth line of each input file. All files\n must be the same length.\n\n";
+}
+
+my @fhs=();
+for my $file (@ARGV) {
+ my $fh;
+ open $fh, "<$file" or die "Can't read $file: $!\n";
+ push @fhs, $fh;
+}
+
+my $first = shift @fhs;
+
+while(my $x = <$first>) {
+ my $ind = 0;
+ chomp $x;
+ my @fields = ($x);
+ for my $fh (@fhs) {
+ $ind++;
+ $x = <$fh>;
+ die "ERROR: Mismatched number of lines: $ARGV[$ind]\n" unless $x;
+ chomp $x;
+ push @fields, $x;
+ }
+ print join ' ||| ', @fields;
+ print "\n";
+}
+my $ind = 0;
+for my $fh (@fhs) {
+ $ind++;
+ my $x=<$fh>;
+ die "ERROR: $ARGV[$ind] has extra lines!\n" if $x;
+}
+
+exit 0;
+
+for my $fh (@fhs) {
+ close $fh;
+}
+