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.
3
Answers
In Python it is easy:
The easiest way for me to do it with shell commands is to show the head 8 lines of original config.xml and deviate the output to a new file. Then append the newfile with your code and finally including the tail of config.xml starting from line 8
Finally you can substitute original config.xml with newfile. Check the content of config.xml before doing it!
In perl such operation can be easily achieved in numerous ways, feel free to choose one which you find favorable
Substitute approach
Array slice approach
Array iteration approach
Input
Output