Add --index parameter to allow selection of nth occurence of field.

This commit is contained in:
Jim Hague 2013-07-16 16:25:30 +01:00
parent 6f50649440
commit e6090d8ef4
1 changed files with 10 additions and 2 deletions

View File

@ -105,11 +105,15 @@ def convertTitle(t, options):
return res return res
def process(inf, options): def process(inf, options):
n = options.index
for line in inf: for line in inf:
line = line.strip() line = line.strip()
if len(line) > 2 and line[0] == options.field and line[1] == ':': if len(line) > 2 and line[0] == options.field and line[1] == ':':
print(convertTitle(line[2:].strip(), options)) if n > 1:
break n = n - 1
else:
print(convertTitle(line[2:].strip(), options))
break
parser = optparse.OptionParser(usage="usage: %prog [options] [filename]\n\n" parser = optparse.OptionParser(usage="usage: %prog [options] [filename]\n\n"
" Extract field data from ABC file.") " Extract field data from ABC file.")
@ -121,6 +125,10 @@ parser.add_option("-m", "--html", dest="html",
parser.add_option("-l", "--latex", dest="latex", parser.add_option("-l", "--latex", dest="latex",
action="store_true", default=False, action="store_true", default=False,
help="format ouput for LaTeX") 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() (options, args) = parser.parse_args()
if options.html and options.latex: if options.html and options.latex: