Created
December 8, 2013 13:09
-
-
Save hideshi/7857187 to your computer and use it in GitHub Desktop.
Show file and filter by keyword like cat and grep.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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