dimanche 3 novembre 2019

Search each line list in a file that contain combination of specific words/string

I'm trying to search specific words from each line of a file and if found that words do something.

I have a file contain list of name for example

pSet02Hw codeid xxxxx
Set01Mt codeid xxxxx
Set02Mt codeid xxxxx
pSet03Hw codeid xxxxx
pSet07Hw codeid xxxxx
pset01hw codeid xxxxx
set03mt codeid xxxxx

I read each line in the file. From the file I would like to search of the line that got set and hw than execute process1 and elif the line got set and mt than execute process2. The code below does not work properly unless i just search for set only but this could lead to wrong process to be executed.

if 'sethw' in linelist[0]:
    execute process1
elif 'setmt' in linelist[0]:
    execute process2
else:
    print("No process executed")
    break

i tried combination of 'set' and 'hw' and combination of 'set' and 'mt' but it does not properly work.

Please advise and show me the right way of doing it. Thank you all.

Aucun commentaire:

Enregistrer un commentaire