add option "-n" ("--line-number")
3 files changed, 19 insertions(+), 7 deletions(-)

M ChangeLog.md
M README.md
M xgrep.py
M ChangeLog.md +7 -0
@@ 1,3 1,10 @@ 
+2020-04-24:
+
+* rename option `-n` (`--declare-ns`) to `-N`
+* add option `-n` (`--line-number`)
+* bump version to 2.7
+
+
 2020-01-14:
 
 * catch keyboard interrupt

          
M README.md +5 -4
@@ 27,7 27,8 @@ Usage:
              [-l] [--files-with-matches]
              [-L] [--files-without-match]
              [-m] [--matches]
-             [-n] [--declare-ns]
+             [-n] [--line-number]
+             [-N] [--declare-ns]
              [-q] [--quiet]
              [-r <ns>] [--regex <ns>]
              <XPath expression>

          
@@ 47,9 48,9 @@ declarations. The `-C` option preserves 
 output through [GNU less](http://www.gnu.org/software/less/) and similar
 programs.
 
-The options `-c`, `-l`, `-L`, and `-q` mimic the behaviour of
-[GNU grep](http://www.gnu.org/software/grep/). The latter option suppresses any
-output, but still returns the exit status (`0` if there are matches, `1` if
+The options `-c`, `-l`, `-L`, `-n`, and `-q` mimic the behaviour
+of [GNU grep](http://www.gnu.org/software/grep/). The latter option suppresses
+any output, but still returns the exit status (`0` if there are matches, `1` if
 there are none, and `2` for errors).
 
 Andreas Nolda (andreas@nolda.org)

          
M xgrep.py +7 -3
@@ 1,6 1,6 @@ 
 #! /usr/bin/python3
 # xgrep.py -- search for elements in XML files, using XPath 1.0 expressions
-# Andreas Nolda 2020-01-14
+# Andreas Nolda 2020-04-24
 
 import sys
 import argparse

          
@@ 8,7 8,7 @@ import re
 from blessings import Terminal
 from lxml import etree
 
-version=2.6
+version=2.7
 
 parser = argparse.ArgumentParser()
 parser.add_argument("expr",

          
@@ 27,7 27,9 @@ parser.add_argument("-L", "--files-witho
                     help="output list of non-matching files")
 parser.add_argument("-m", "--matches", action="store_true",
                     help="output list of matches")
-parser.add_argument("-n", "--declare-ns", action="store_true",
+parser.add_argument("-n", "--line-number", action="store_true",
+                    help="output line number of match start")
+parser.add_argument("-N", "--declare-ns", action="store_true",
                     help="declare namespaces in matches")
 parser.add_argument("-q", "--quiet", action="store_true",
                     help="only return exit status")

          
@@ 94,6 96,8 @@ def print_match(match, int):
             print(term.bold("{0}[{1}]".format(args.expr, int)) + ":")
         else:
             print(term.bold(args.expr) + ":")
+    if args.line_number:
+        print(term.bright_black("{0}".format(match.sourceline)) + ":", end="")
     if args.declare_ns:
         print(serialize_match(match))
     else: