changeset 316:eedf65564226

Add --index parameter to allow selection of nth occurence of field.
author Jim Hague <jim.hague@acm.org>
date Tue, 16 Jul 2013 16:25:30 +0100
parents b4d568b70c33
children 01399eb43c0d
files abcfield.py
diffstat 1 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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: