I having a little trouble to figure out how can I replace the specific lines in a text file by the lines from another text file marching certain pattern. !?!? For example:
I have two files: file1 and file2 , I want to search lines of the first file for specific keywords and then take this lines of the text and replace it in another text file which having a same keywords.
keyword = [word1,word2,wor3,word4] file1=open("file1.txt", 'r').read() file2=open("file2.txt", 'r+w').read() for i in keyword: for line in file1: if i in line: # do replace the lines in file2 marching keyword ? '''and here I am stuck.... How can I search for lines in second file and then replace this lines by another ones from first file1?'''
Edited 6 Years Ago by deonis: n/a