#!/bin/sh -- # This comment tells perl not to loop! eval 'exec /usr/bin/perl -S $0 ${1+"$@"}' if 0; use English; $OUTPUT_AUTOFLUSH = 1; # Don't buffer stdout #----------------------------------------------------- # HABASH Sat Feb 7 17:00:06 EST 2004 # deinterleave.pl #----------------------------------------------------- $argc = @ARGV; if ($argc < 1) {die("Usage: $0 +\n");} for ($i=0; $i<$argc;$i++){ $file = $ARGV[$i]; $ext =$file; $ext=~s/.*\-(\S+)/$1/; $dir=$file; $dir=~s/(.*)\/[^\/]+/$1/; if ($dir eq $file){$dir="."} unless (open(INP,$file)) { die ("Cannot open input file $file"); } @header=@footer=%combo=(); $name=""; while ($line=){ if ($line=~/^\@/) {@header = (@header , $line)} if ($line=~/^\[/) { $name=$line; chomp($name); $name=~s/\[(wpos=)?\d+\,(....)\-\d+.*/$2/; print STDERR "detecting $name\n"; $combo{$name}=$combo{$name}.$line; } if ($line=~/^\(/) {@footer = (@footer , $line)} } close(INP); foreach $file (keys %combo){ print STDERR "printing $dir/$file-$ext\n"; unless (open(OUT,">$dir/$file-$ext")) { die ("Cannot open output file $dir/$file-$ext"); } foreach $h (@header){ print OUT $h; } print OUT "\n"; print OUT $combo{$file}; foreach $f (@footer){ print OUT $f; } close(OUT); } }