Я создал скрипт Python, чтобы сделать это для вас.Скопируйте содержимое в filename.py
, примените sudo chmod +x filename.py
и выполните сценарий.Я предположил, что вы использовали file1.xml
в качестве XML-файла.
#!/usr/bin/python
import re
your_content: "the words to replace the string"
# here we read the file in Python
fh = open("file1.xml", "r")
content = fh.read()
# Here we match the string, it matches content between =name=" and \
m = re.sub(r'(?<=name=\")(.*)(?=\")', your_content, content)
print(m)
# now you probably want to write to the file
x = open("file1.xml", "w")
x.write(m)
Обратите внимание, Python 3 также работает.