In article <[EMAIL PROTECTED]>,
Frank Nordberg  <[EMAIL PROTECTED]> wrote:

> I suppose you could do that with grep, but there are lots of people here
> that knows more than me about that.

Here's a little Perl program that may go some distance towards what
Robert wants:

--- cut here ---
#!/usr/bin/perl
# abc2chord.pl
# 19 Sep 2000 Anselm Lingnau <[EMAIL PROTECTED]>

use Getopt::Long;

$keep = "XTMK";

GetOptions("keep=s" => \$keep);

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

The most conspicuous omission is that it doesn't »optimize« alternate
endings that contain the same chords. (This is left to the reader as an
exercise).

Here's the output from Frank's source:

  ; perl ./abc2chord.pl --keep XTMKR ~/Music/ScatterTheMud.abc
  X:1
  T:Scatter the Mud
  R:Jig
  M:6/8
  K:ADor
  Am G | Am Em | Am | G | Am | Am | Em |[1 G Am :|[2 G Am ||
  |: Am G | G | Am Em | G | Am G | G | Em |[1 G Am :|[2 G Am |

Anselm
-- 
Anselm Lingnau ......................... [EMAIL PROTECTED]
When one is in love, one always begins by deceiving oneself, and one always
ends by deceiving others. That is what the world calls a romance.
                                                                 -- Oscar Wilde
To subscribe/unsubscribe, point your browser to: http://www.tullochgorm.com/lists.html

Reply via email to