I have a file with Contents as below:-
He is good at python.
Python is not a language as well as animal.
Look for python near you.
Hello World it's great to be here.
Now, script should search for pattern "python" or "pyt" or "pyth" or "Python" or any regex related to "p/Python". After search of particular word, it should insert new word like "Lion". So output should become like below:-
He is good at python.
Lion
Python is not a language as well as animal.
Lion
Look for python near you.
Lion
Hello World it's great to be here.
How can I do that ?
NOTE:- Till now I wrote code like this:-
def insertAfterText(args):
file_name = args.insertAfterText[0]
pattern = args.insertAfterText[1]
val = args.insertAfterText[2]
fh = fileinput.input(file_name,inplace=True)
for line in fh:
replacement=val+line
line=re.sub(pattern,replacement,line)
sys.stdout.write(line)
fh.close()