Modifying a row record in an XML file with a shell script

Source: Internet
Author: User

Modifying a row record in an XML file with a shell script

As before, suppose the following XML file:

Web.xml has the following contents:

	<param-name>cookieName</param-name>
	<param-value>sessionName</param-value>

Requirements: Now you need to replace the value of cookiename with a shell script,

Use the shell to implement the following methods:

Shell Script section:


Declare-i Dline

Getline ()
{
Grep-n "CookieName" ${domain_home}/portal/root/web-inf/web.xml | head-1 | Cut-d ":"-f 1;
}


Getlinenum ()
{
awk "Begin{a= ' getline"; b= "1"; c= (a+b);p rint C} ";
}


Dline= ' Getlinenum ';
echo "line is ${dline}";
Sed-i "${dline},${dline}s/.*/\<param-value\> replacement value \<\/param-value\>/g" Path/web.xml


Description: The difference between this and the previous replacement attribute file is that it is positioned exactly to the line and then replaces the line code.

This XML and properties are the only things that need to be replaced by default.



Related Article

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.