Search Multiple Strings (from File) in a file and print the line

后端 未结 3 1411
無奈伤痛
無奈伤痛 2021-01-23 22:13

Again apologies for been noob here: Trying below code for searching multiple strings read from keywords and search in f and printing the line. It works if I have on

3条回答
  •  情话喂你
    2021-01-23 22:31

    #The Easiest one...
    def strsearch():
    
      fopen = open('logfile.txt',mode='r+')
    
      fread = fopen.readlines()
    
      x = 'Product Name'
    
      y = 'Problem Description'
    
      z = 'Resolution Summary'
    
      for line in fread:
    
          #print(line)
    
           if x in line:
    
               print(line)
    
           if y in line:
    
               print(line)
    
           if z in line:
    
               print(line)
    

    strsearch()

提交回复
热议问题