Skip to content

Instantly share code, notes, and snippets.

@hideshi
Created December 8, 2013 13:09
Show Gist options
  • Save hideshi/7857187 to your computer and use it in GitHub Desktop.
Save hideshi/7857187 to your computer and use it in GitHub Desktop.
Show file and filter by keyword like cat and grep.
import sys
import os
def main(args):
directory = args[1]
if len(args) > 2:
keyword = args[2]
else:
keyword = ''
file_list = os.listdir(directory)
for item in file_list:
if os.path.isfile(item) and 'py' in item:
for line in open(item):
if keyword == '' or keyword in line:
print(str(item) + ' ', end='')
print(line, end='')
if __name__ == '__main__':
main(sys.argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment