#!/usr/bin/perl

use strict;
use warnings;

my $file = $ARGV[0];
open my $lines, $file or die "Could not open $file: $!";
my $title = '';
my $save = 0;

while(my $line = <$lines>) {
	chomp($line);
	if($title eq '') {
		$title = $line;
		print "$title\n";
		next;
	}
	
	if($file =~ /006727/) {
		if($line eq '') {
			next;
		}
		print "$line\n";
	} else {
		$line =~ s/^[\s"]+//;
		$line =~ s/[\s"]+$//;
		if($line eq '' or index($line, '#') eq 0) {
			$save = 0;
			next;
		}
		if(index($line, '>') eq 0) {
			$save = 1;
			next;
		}
		if(index(uc $line, 'DAMARA:') eq 0) {
			$line =~ s/\[.*//g;
		}
		if(($save or $line =~ /^[^\s]+:/) and index($line, '*') ne 0) {
			print "$line\n";
		}
	}
}

close $lines;
