I am creating a script script1.sh
through which I have to change an xml file( abc.xml
) contents. The contents of xml file are
area = xyz/a
url = "sqlserver://servername:portno/a"
username=""
password=""
area = xyz/b
url = "sqlserver://servername:portno/b"
username=""
password=""
I have to change servername
, portno
, username
and password
for both area using script1.sh
. Servername
and portno
will be same for both area but username
and password
will differ. So how can I make changes from script1.sh
to abc.xml
sed -i 's/$strurl/$url/g' context.sh
This is how I am searching but can't search and change url rest all are fine. I think the url string is too big to be searched.
sed -i 's!$strurl!$url!g' filename
这将是答案,因为url本身包含'/'作为分隔符,因此我们需要在sed命令中使用其他分隔符
You can use sed
with option -i
to change a file in-place.
sed -i 's/what/towhat/g' filename.txt
In case your what
contains slashes ( /
) itself, use any other character (eg ,
) which does not appear in the what
or the towhat
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.