Linked Questions

Popular Questions

How to remove all lines above a certain line in python

Asked by At

I have an html file where I want to remove all lines above the line starting with string <!DOCTYPE html


HTTP/1.1 400 Bad Request
Content-Type: text/html; charset=utf-8
Date: Sat, 22 Mar 2015 07:56:52 
Connection: close
Content-Length: 2959

<!DOCTYPE html...... extra lines ...

So when I search for the occurrence of string <!DOCTYPE I need to remove all lines including blank ones above this particular line. In linux we have an option in grep which can search for the lines above and below and then delete it. Can we do a similar thing in Python?

Related Questions