Issue
I have a linux centos 7 server and i want Below lines to file with name config.xml
<vhostMap>
<vhost>google</vhost>
<domain>google.com, www.google.com</domain>
</vhostMap>
i want add this lines after line 8 at config.xml file
how its possible with sed or awk command? its python or perl? i have searched much, but its hard for me as im noob, can someone tell me some example?
Thanks.
Solution
In Python it is easy:
to_add = """<vhostMap>
<vhost>google</vhost>
<domain>google.com, www.google.com</domain>
</vhostMap>
"""
with open("config.xml", "r") as f:
all_lines = f.readlines()
with open("config.xml", "w") as f:
for l in all_lines[:8]: f.write(l)
f.write(to_add)
for l in all_lines[8:]: f.write(l)
Answered By - Błotosmętek Answer Checked By - Robin (WPSolving Admin)