sed find replace after HOST string

Hi Everyone,

I have a xml file, where i need to find this

HOST=dbhost.domain.com

and then replace only
dbhost.domain.com with db.one.in

so finally it should like this

HOST=db.one.in

i tried this but its not working.

sed -i "s/^HOST=*com$/HOST=db.one.in/g" repository.xml

^ i have used for starting of string and $, i have used for end of string.

Thanks in Advance.

In which way "its not working"?

Do you know the difference of * in regular expressions (as used by e.g. sed ) and shell "pathname expansion / pattern matching" ?
Are you sure there's NO other character on that line, e.g. leading white space?
Why do you specify the g flag for global / overall substitution when you try to match the entire line?

Rudic Sir,

* represents everything. and * is also used for path name expansion.

Sir, this is the entire line

<param name="url" value="jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=dbhost.domain.com)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=DBSID)))"/>

g i have used because i want to make changes through out the file.

True for expansion, false for regexes. . is the wild card in regexes (c.f. man regex ).

/^HOST.../ will match the "HOST" word at the begin of the line - so will NEVER match your sample.

sed commands / scripts operate on lines, and line per line on entire files (unless told otherwise). The g flag repeats the operation for every occurrence of the regex on the respective line.

Try

sed -i 's/HOST=[^)]*com/HOST=db.one.in/' repository.xml
1 Like

Thanks Rudic Sir, your code works.

Thanks to you. Great.

---------- Post updated at 06:21 AM ---------- Previous update was at 06:20 AM ----------

Rudic Sir, I will also answer questions on this forum, that are of my standard.
Thanks Sir.