python - Insert new line before multiple keywords in text file -


i have following text:

"this problem. extract data document. text looking for. not happening"

i able insert new line after multiple keywords:

import fileinput line in fileinput.input('text.txt', inplace=1):     print line,     if line.startswith(('extract',  'text')):         print ' ' 

but cannot find solution adding newline before keywords.

final format should like:

"this problem.

extract data document.

text looking for. not happening"

the issue words can change keywords. looking editing text containing keywords.

thanks suggestions.

do mean:

import fileinput line in fileinput.input('text.txt', inplace=1):     if line.startswith(('extract',  'text')):         print '\n'+line+'\n'         else:             print line 

?


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -