I have text file where is probably sometimes one line too much and i have to delete it. Not always but still need to check it everytime.
The phrase always includes the same words at the beginning, but end of the line are maybe different, howefever full line need to delete.
Example:
This is original lines in middle of txt file:
.........
<br>rrrrr TTTTTT ffgggggggg
<br>ja UOOOOOOOO on >= 16 täysin.
<br>ja numeroyhdistelmä on 9- 39- 9
<br>ja href="./reeeee.html">wwwwjjhjhkkghjky. </a> </td>
</tr></TABLE>
<table border=0 cellpadding= 25 width= 560><TR><TD width=80></TD><TD
width=240><PRE>
.........
after python code lines would be:
.........
<br>rrrrr TTTTTT ffgggggggg
<br>ja UOOOOOOOO on >= 16 täysin.
<br>ja href="./reeeee.html">wwwwjjhjhkkghjky. </a> </td>
</tr></TABLE>
<table border=0 cellpadding= 25 width= 560><TR><TD width=80></TD><TD
width=240><PRE>
.........
So line what need delete is:
<br>ja numeroyhdistelmä on 9- 39- 9
If i use letter "ä" to the code it gives some "unicode" errors but i havent choice try something else word to search because beginning the line are somewhere else too and values "9- 39- 9" probably change.
This what i was try:
f = open("text2.txt","r+")
d = f.readlines()
f.seek(0)
for line in d:
if "numeroyhdistelmä" in line:
f.write(line)
f.truncate()
f.close()
I think letter "ä" is not only problem because i was testing this code some other search word and it delete all lines in a text file.
Thanks!