Swadhin Ray
asked on
search partial string from a file and replace with another string using batch script and shell script
Hello Experts,
I need a batch file and a shell script for searching one string and replacing with other in an existing XML file.
Here is my XML file called "ran.xml":
from the above script i have to search for :
<PROPERTY NAME="DBURL">..
then replace it with :
<PROPERTY NAME="DBURL">REP/STORE/CAL L/DBURL</P ROPERTY>
I have to search the initial only and then replace it with final string.
I need a batch file and a shell script for searching one string and replacing with other in an existing XML file.
Here is my XML file called "ran.xml":
<?xml version="1.0"?>
<!DOCTYPE MODULE SYSTEM "file://localhost/SYSTEMi_HOME_UNIX/Systemi/Doc/Module.dtd" [
<!ENTITY license SYSTEM "file://localhost/SYSTEMi_HOME_UNIX/Systemi/keys/CENTNAME_license.xml">
<!ENTITY hostname "CENTHOSTNAME">
]>
<MODULE NAME="ABC in Single Node" INDEX="&index;">
<SYSTEM>
<PROPERTIES>
<!-- Begin Client App/Web Server related Properties -->
<PROPERTY NAME="BC_TIMEOUT">90</PROPERTY>
<!--End DB related items -->
<INSTANCE>
<PROPERTY NAME="DBURL">CDBURL</PROPERTY>
<PROPERTY NAME="DBUSER">CDBUSER</PROPERTY>
</INSTANCE>
<!--Begin Log related items -->
<PROPERTY NAME="LOGFILE">&systemi_root;/Systemi/log/client&node_id;_{0,date,MMM-dd-yy-HH-mm-ss}</PROPERTY>
<PROPERTY NAME="LOG_ENCODING">UTF-8</PROPERTY>
<!--End Log related items -->
</PROPERTIES>
</SYSTEM>
</MODULE>
from the above script i have to search for :
<PROPERTY NAME="DBURL">..
then replace it with :
<PROPERTY NAME="DBURL">REP/STORE/CAL
I have to search the initial only and then replace it with final string.
ASKER
I am getting the below error:
[root@msi-vmappleap1 sloba]# sed -i.bak 's@\(<PROPERTY NAME="DBURL">\).*$@\jdbc:o racle:thin :@slobadb: 1521:db11g </PROPERT@ ' ran.xml
sed: -e expression #1, char 54: unknown option to `s'
[root@msi-vmappleap1 sloba]# sed -i.bak 's@\(<PROPERTY NAME="DBURL">\).*$@\jdbc:o
sed: -e expression #1, char 54: unknown option to `s'
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks a lot
If so, here is a one-liner:
Open in new window
The above will create a backup file "ran.xml.bak" to then change "ran.xml" in place.