Created
October 18, 2017 14:48
-
-
Save iamn3/d7a30f31ff53f1c07374ab5d226cbc3c to your computer and use it in GitHub Desktop.
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 | |
if __name__ == "__main__": | |
if len(sys.argv) != 3: | |
print("Useage: %s [word] filename" % sys.argv[0]) | |
quit() | |
word = sys.argv[1] # 検索対象の文字列 | |
fp = open(sys.argv[2],'r') | |
data = fp.read().split("\n") #ファイル内のデータ | |
fp.close() | |
# 1行ずつ対象の文字列を含む行があるか調ベて見つけたら表示する | |
for line_num in range(0, len(data)): | |
if word in data[line_num]: | |
print("%s : %s" % (line_num + 1,data[line_num])) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment