#!/usr/bin/env perl

use strict;
use warnings;
use FileHandle;

my $file;

for $file (@ARGV) {
    my $found = 0;
    my $line;

    my $handle = new FileHandle $file;
    if (not defined $handle) {
        die "Can't open $file.";
    } 
    
    # Skip to the good stuff
    while ($line = <$handle>) {
        if ($line =~ "^Query=") {
            $found = 1;
            print $line;
            last;
        }
    }

    # Print out everything that's good
    if ($found) {
        my $in_table = 0;
        while ($line = <$handle>) {
            if ($line =~ /\|/) {
                $in_table = 1;
            } elsif ($in_table && $line =~ /^\s/) {
                last;
            }
            print $line;
        }
    }
    print "\n\n";
}

exit (0);
