From 940c4545669bfdc63a374f8733819d41686008c3 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Fri, 8 Nov 2013 04:53:34 -0500 Subject: Add -j option to striplog. --- devtools/striplog | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'devtools/striplog') diff --git a/devtools/striplog b/devtools/striplog index d1c9fe11..9c82e5a3 100755 --- a/devtools/striplog +++ b/devtools/striplog @@ -2,7 +2,7 @@ # # striplog -- strip leading lines from logs # -# striplog -1 strips the first line only. +# striplog -j strips JSON leader sentences. # striplog with no option strips all leading lines beginning with # # # This file is Copyright (c) 2010 by the GPSD project @@ -10,9 +10,9 @@ # import getopt, sys -secondline = firstline = False +secondline = firstline = stripjson = False stripval = 0 -(options, arguments) = getopt.getopt(sys.argv[1:], "12n:") +(options, arguments) = getopt.getopt(sys.argv[1:], "12n:j") for (switch, val) in options: if (switch == '-1'): firstline = True @@ -20,6 +20,8 @@ for (switch, val) in options: secondline = True if (switch == '-n'): stripval = int(val) + if (switch == '-j'): + stripjson = True try: if firstline: @@ -30,6 +32,17 @@ try: elif stripval: for _dummy in range(stripval): sys.stdin.readline() + elif stripjson: + while True: + line = sys.stdin.readline() + if line.startswith('{"class":"VERSION"') \ + or line.startswith('{"class":"DEVICE"') \ + or line.startswith('{"class":"DEVICES"') \ + or line.startswith('{"class":"WATCH"'): + continue + else: + break + sys.stdout.write(line) else: while True: line = sys.stdin.readline() -- cgit v1.2.1