I have a text file with some data, I want to read the file line by line then do find and replace.
In the text file i want to find "_x" and replace it with it's second previous line, that means i want the final output file like following
input
a
a=10
c=_x
b
b=20
d=_x
Output
a
a=10
c=a
b
b=20
d=b
I have tried to read the file line by line but i couldn't. How to read a text file line by line and replace the word with it's second previous line????