[Shell] modifying XML content

Source: Internet
Author: User

It is easier to parse and modify XML using python, but if it is not convenient to use python, you can simply replace it with the SED command

For example, to replace the value of the port number in the following line:

<Param name = "ftpport"> 21 </param>

You can use:

New_port = "22" sed '/\ <ftpport \>/S/[0-9] \ {2, 5 \}/' "$ new_port" '/'old. XML> New. XML

Note:

<And> used to match word boundaries.

S indicates replacing the matched rows.

[0-9] {2, 5} indicates that the replaced source is 2 ~ 5-digit, which is a regular expression

Of course, for some characters with special meanings in shell, add \ escape and pass it to SED

'"$ New_port"' uses a shell tip to pass the variable value to sed. Make sure that the port is replaced with 22 instead of the $ new_port string, you can try to remove the four quotation marks before and after $ new_port.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.