#!/usr/bin/perl
# abc2chord.pl
# Posted to abcusers 19 April 1999
# From: Anselm Lingnau <anselm@strathspey.de>

use Getopt::Long;

$keep =3D "XTMK";

GetOptions("keep=3Ds" =3D> \$keep);

while (<>) {
    # keep only header lines listed on --keep=3D... option
    if (($header) =3D /^([A-Z]):/) {
        print if $header =3D~ /[$keep]/o;
        next;
    }
    $_ .=3D <> while /\\$/;     # merge continued lines
    $_ =3D join(' ', /(?:"(.*?)")|(:?\|(?:\||:|\[\d)?)/g); # extract chor=
ds &c.
    s/^ *//; s/ +/ /g;          # remove extraneous whitespace
    s/\| \|/| - |/g;            # add placeholders for no-chord bars
    print $_, "\n";
}

