# HG changeset patch # User Jim Hague # Date 1373988330 -3600 # Node ID eedf6556422602b8437e3c1f7db59f4bd7704777 # Parent b4d568b70c33cb6e8354ab6c594c1d6aa2541e44 Add --index parameter to allow selection of nth occurence of field. diff -r b4d568b70c33 -r eedf65564226 abcfield.py --- a/abcfield.py Fri Jul 12 14:27:41 2013 +0100 +++ b/abcfield.py Tue Jul 16 16:25:30 2013 +0100 @@ -105,11 +105,15 @@ return res def process(inf, options): + n = options.index for line in inf: line = line.strip() if len(line) > 2 and line[0] == options.field and line[1] == ':': - print(convertTitle(line[2:].strip(), options)) - break + if n > 1: + n = n - 1 + else: + print(convertTitle(line[2:].strip(), options)) + break parser = optparse.OptionParser(usage="usage: %prog [options] [filename]\n\n" " Extract field data from ABC file.") @@ -121,6 +125,10 @@ parser.add_option("-l", "--latex", dest="latex", action="store_true", default=False, help="format ouput for LaTeX") +parser.add_option("-n", "--index", dest="index", + action="store", type="int", default=1, + help="report INDEXth value [default: %default]", + metavar="INDEX") (options, args) = parser.parse_args() if options.html and options.latex: