Python delete lines of text line #1 till regex -



Python delete lines of text line #1 till regex -

i have issue can't seem find solution within python.

from command line can by: sed '1,/commands/d' /var/tmp/newfile

this delete line #1 till regex "commands". simple

but can't same python can find. re.sub , multiline doesn't seem work.

so have question how can in pythonic way? rather not run sed within python unless have to.

i utilize fileinput inplace=true alter original file setting flag when find match , removing lines until do:

import fileinput import re found = false line in fileinput.input("your_file",inplace=true): if re.match("pattern",line): found = true if found: print(line,end="") # print line, python2 else: print(end="") # print, python2

if there nil complex pattern if "pattern" in line may work.

python regex

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -