0

I am completely new at Python and I am not sure where to start with this task.
Basically, I want to search for a word in each line; if the word is there, output the entire line to another file (Excel or Text).

The lines look like this:
PA,IAV protein,AC0T9,DHP of IAV,2znl-A+z327-A
PPM1B,IHP of IAV,MAGEA2B,DHP of IAV,2p8e-A+z097-a

So, if the line contains IAV protein, I would like to copy the whole first line.

I don't need someone to just give me a code that works (although I won't refuse it...) but if you could point me in the right direction, that would be much appreciated.

Thanks

2
Contributors
3
Replies
5
Views
5 Years
Discussion Span
Last Post by pyTony
0

You must tell more clearly what would be expected output. There is also three kinds of IAV bits of info on lines:
"DHP of IAV"
"IHP of IAV" and
"IAV"

>>> if 'IAV' in "PA,IAV protein,AC0T9,DHP of IAV,2znl-A+z327-A":
    print('IAV in line')


IAV in line
>>> 
0

I would like to output the entire line that contains that phrase.
So if I had the two lines
PA,IAV protein,AC0T9,DHP of IAV,2znl-A+z327-A
PPM1B,IHP of IAV,MAGEA2B,DHP of IAV,2p8e-A+z097-a

I would want to output
PA,IAV protein,AC0T9,DHP of IAV,2znl-A+z327-A
into a text file since it contains "IAV protein"
It's gotta be the whole phrase "IAV protein" rather than just "IAV"

Also, since I am looking through an entire text file, how would I search the whole file?

Edited by Doormail11: Forgot to add it

0

something like

with open('data.txt') as datain, open('dataout.txt', 'w') as dataout:
    for d in datain:
        if 'IAV protein' in d:
            dataout.write(d)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.