I'm trying to write a simple python script where
- it takes values from stdin
- replaces a specific matched word
- passes on the output with the NEW value back to stdout
I only have the part where it takes the values from stdin and looks for the matching words, I'm a bit stuck after that.
import re
import sys
for line in sys.stdin:
matchObj = re.search(r'<something>(.*)</something>',line)
if matchObj:
oldWord = matchObj.group(1)
print oldWord
Contents of foo
<something>REPLACEME</something>
<blah>UNTOUCH</blah>
Ideally if I run this command
cat foo | ./test.py
I would get something like this
<something>NEWWORD</something
<blah>UNTOUCH</blah>
re.sub().