BLOG(6)BLOG MANUALBLOG(6)
NAME A simple python grep SYNOPSIS

Here's a simplistic text search script (python grep) that can be run quickly from a Windows command line and used to search both local and network mapped drives.

DESCRIPTION

import os
import sys

if sys.argv[1] == '':
    print "Usage: python grep.py searchterm pathtosearch"
    sys.exit()
searchterm = sys.argv[1]
pathtosearch = sys.argv[2]
os.chdir(pathtosearch)
for root,dir,files in os.walk(pathtosearch):
    for fi in files:
        path = os.path.join(root,fi)
        for num,line in enumerate(open(path)):
            if searchterm.upper() in line.upper():
                print "[%s] found in [%s] , line number [%d]" %(searchterm.upper(),path,num+1)

SEE ALSO      appletonmakerspace(1), github(1), instagram(6), mastodon(6), wisconsinlinux(1), youtube(6) AUTHORS Mike Putnam mike@theputnams.net FILES2023-12-09-100-hours-1000-kilometers2017-07-06-whats-going-on-in-tech2017-04-26-git-blame2016-10-27-choose-your-own-adventure-lockin2016-09-23-the-zen-of-python2016-07-18-organize-your-docker-stuff-with-labels2016-02-15-tail-foreverjs-logs2015-06-30-coder-cooperative2014-09-28-learning-to-weld2014-05-04-a-copper-thing2014-05-01-openbsd-55-released-today2014-04-30-what-to-make2013-10-10-appleton-makerspace-grand-opening2012-11-11-dell-xps-13-ultrabook-running-openbsd-snapshot2011-09-28-why-i-love-barcamp2011-07-04-a-simple-python-grep2011-05-08-dhmn-candybot-won2011-04-14-milwaukee-makerspace-grand-opening-road-trip2011-03-17-what-the-heck-is-a-barcamp2011-02-21-arduino-mosfet-irobot-wheels2011-02-05-dhmn-make-session2011-02-01-gladiator-girl2011-01-31-toward-an-appleton-wi-makerspace2011-01-24-madhackerhaus-12011-01-16-a-timelapse-doodle2010-11-07-arduino-happy-birthday-emitter2002-07-08-self-hosted-linux2002-04-08-geocaching More posts... (press for help or to quit)
BLOG(6)BLOG MANUALBLOG(6)
Mike Putnam