[Assorted-commits] SF.net SVN: assorted:[1483] shell-tools/trunk/src/hdr-grep.py
Brought to you by:
yangzhang
From: <yan...@us...> - 2009-10-14 04:52:54
|
Revision: 1483 http://assorted.svn.sourceforge.net/assorted/?rev=1483&view=rev Author: yangzhang Date: 2009-10-14 04:52:45 +0000 (Wed, 14 Oct 2009) Log Message: ----------- added hdr-grep Added Paths: ----------- shell-tools/trunk/src/hdr-grep.py Added: shell-tools/trunk/src/hdr-grep.py =================================================================== --- shell-tools/trunk/src/hdr-grep.py (rev 0) +++ shell-tools/trunk/src/hdr-grep.py 2009-10-14 04:52:45 UTC (rev 1483) @@ -0,0 +1,20 @@ +#!/usr/bin/env python + +""" +Prints the titles of sections in stdin whose bodies contain the given query +text (case-insensitive). Assumes input is markdown-/pandoc-formatted and only +looks for level-1 and -2 headers (lines that are underlined with at least 3 = +or - characters). +""" + +from commons.seqs import pairwise +import sys + +query = sys.argv[1] +hdr = None +for prev, line in pairwise(line.rstrip() for line in sys.stdin): + if len(line) >= 3 and set(line) in [set('-'), set('=')]: + hdr = prev + elif hdr is not None and query.lower() in line.lower(): + print hdr + hdr = None Property changes on: shell-tools/trunk/src/hdr-grep.py ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |