Re: Grepping words for match in a file

2019-12-28 Thread DL Neil via Python-list
On 29/12/19 5:14 AM, Dan Sommers wrote: On 12/28/19 12:29 AM, Mahmood Naderan via Python-list wrote: Hi I have some lines in a text file like ADD R1, R2 ADD3 R4, R5, R6 ADD.MOV R1, R2, [0x10] If I grep words with this code for line in fp: if my_word in line: Then if my_word is "ADD", I get

Re: Grepping words for match in a file

2019-12-28 Thread Dan Sommers
On 12/28/19 12:29 AM, Mahmood Naderan via Python-list wrote: Hi I have some lines in a text file like ADD R1, R2 ADD3 R4, R5, R6 ADD.MOV R1, R2, [0x10] If I grep words with this code for line in fp: if my_word in line: Then if my_word is "ADD", I get 3 matches. However, if I grep word with t

Re: Grepping words for match in a file

2019-12-28 Thread Dan Sommers
On 12/28/19 12:29 AM, Mahmood Naderan via Python-list wrote: Hi I have some lines in a text file like ADD R1, R2 ADD3 R4, R5, R6 ADD.MOV R1, R2, [0x10] If I grep words with this code for line in fp: if my_word in line: Then if my_word is "ADD", I get 3 matches. However, if I grep word with t

Re: Grepping words for match in a file

2019-12-28 Thread Jason Friedman
> > > I have some lines in a text file like > ADD R1, R2 > ADD3 R4, R5, R6 > ADD.MOV R1, R2, [0x10] > Actually I want to get 2 matches. ADD R1, R2 and ADD.MOV R1, R2, [0x10] > because these two lines are actually "ADD" instructions. However, "ADD3" is > something else. > >>> s = """ADD R1, R

Grepping words for match in a file

2019-12-28 Thread Mahmood Naderan via Python-list
Hi I have some lines in a text file like ADD R1, R2 ADD3 R4, R5, R6 ADD.MOV R1, R2, [0x10] If I grep words with this code for line in fp: if my_word in line: Then if my_word is "ADD", I get 3 matches. However, if I grep word with this code for line in fp: for word in line.split():