I have a f1.txt and f2.po file and I want to replace certain lines (that contains the string "msgstr") in this f2.po file with lines in the f1.txt file.
I mean, the first line that contains the string "msgstr" should replace with the first line in the .txt file and the second line that contains the string "msgstr" should replace with the second line in the .txt file. I hope I've been able to explain it completely.
I know how to overwrite a file but I can't figure out how to overwrite only certain lines. I'de be very appreciated if you could help.
You can walk through the file
f2.poand whenever a line contains"msgstr", callreadlineto ask for the corresponding line inf1.txtand if not, keep the original one.Alternatively, if you don't want to modify
f2.poinplace, add a thirdopen: