I have following lines in a file. I want to read the file after it found certain string.
This is 1st line
This is 2nd line
This is 3rd line
This is 4th line
This is 5th line
Here if the string "3" is found i want to copy all the lines after this into a another file.
My output should be:
This is 3rd line
This is 4th line
This is 5th line in another file.
My code is:
file1=open("file1.txt","r")
file2=open("file2.txt","w")
line=fo.readlines()
for line in lines:
if "3" in line:
print line
file2.write(line)
It print only this line alone "This is 3rd line" Its not printing all the lines after this line??
sed -n '/3/,$p'to print out all the lines after a line contains "3".