Skip to content

Instantly share code, notes, and snippets.

@iamn3
Created October 18, 2017 14:48
Show Gist options
  • Save iamn3/d7a30f31ff53f1c07374ab5d226cbc3c to your computer and use it in GitHub Desktop.
Save iamn3/d7a30f31ff53f1c07374ab5d226cbc3c to your computer and use it in GitHub Desktop.
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