sed find replace after HOST string


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers sed find replace after HOST string
# 1  
Old 03-13-2018
sed find replace after HOST string

Hi Everyone,

I have a xml file, where i need to find this
Code:
HOST=dbhost.domain.com

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

so finally it should like this

Code:
HOST=db.one.in

i tried this but its not working.

Code:
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.


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 03-13-2018 at 07:19 AM.. Reason: Added CODE tags.
# 2  
Old 03-13-2018
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?
# 3  
Old 03-13-2018
Rudic Sir,

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

Sir, this is the entire line

Code:
<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.

Moderator's Comments:
Mod Comment Seriously: Please use CODE tags as required by forum rules!

Last edited by RudiC; 03-13-2018 at 07:42 AM.. Reason: Added CODE tags.
# 4  
Old 03-13-2018
Quote:
Originally Posted by shajay12
Rudic Sir,

* represents everything. and * is also used for path name expansion.
True for expansion, false for regexes. . is the wild card in regexes (c.f. man regex).

Quote:
Sir, this is the entire line

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

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

Quote:
g i have used because i want to make changes through out the file.
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
Code:
sed -i 's/HOST=[^)]*com/HOST=db.one.in/' repository.xml

This User Gave Thanks to RudiC For This Post:
# 5  
Old 03-13-2018
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to identify delimiter to find and replace a string with sed?

I need to find and replace a date format in a SQL script with sed. The original lines are like this: ep.begin_date, ep.end_date, ep.facility_code, AND ep.begin_date <= '01-JUL-2019' ep.begin_date, ep.end_date, ep.facility_code, AND ... (15 Replies)
Discussion started by: duke0001
15 Replies

2. Shell Programming and Scripting

Replace string in XML file with awk/sed with string from another

Sorry for the long/weird title but I'm stuck on a problem I have. I have this XML file: </member> <member> <name>TransactionID</name> <value><string>123456789123456</string></value> </member> <member> <name>Number</name> ... (9 Replies)
Discussion started by: cozzin
9 Replies

3. Shell Programming and Scripting

Sed: find and replace backwards, until string

Some help please: Need to find string ||(everything in front of it)B0300|| and replace it with ||0|| globally In: 16112121||||0||0||0||0||0||52||52||0||0||0||0||1507200053342B0300||1507200053342B0300||0||0||0||0700 Out: 16112121||||0||0||0||0||0||52||52||0||0||0||0||0||0||0||0||0||0700 ... (4 Replies)
Discussion started by: drbiloukos
4 Replies

4. Shell Programming and Scripting

Help with Passing the Output of grep to sed command - to find and replace a string in a file.

I have a file example.txt as follows :SomeTextGoesHere $$TODAY_DT=20140818 $$TODAY_DT=20140818 $$TODAY_DT=20140818I need to automatically update the date (20140818) in the above file, by getting the new date as argument, using a shell script. (It would even be better if I could pass... (5 Replies)
Discussion started by: SriRamKrish
5 Replies

5. Shell Programming and Scripting

HPUX find string in directory and filetype and replace string

Hi, Here's my dilemma. I need to replace the string Sept_2012 to Oct_2012 in all *config.py files within the current directory and below directories Is this possible? Also I am trying to find all instances of the string Sept_2012 within files in the current directory and below I have... (13 Replies)
Discussion started by: pure_jax
13 Replies

6. Shell Programming and Scripting

sed or awk command to replace a string pattern with another string based on position of this string

here is what i want to achieve... consider a file contains below contents. the file size is large about 60mb cat dump.sql INSERT INTO `table1` (`id`, `action`, `date`, `descrip`, `lastModified`) VALUES (1,'Change','2011-05-05 00:00:00','Account Updated','2012-02-10... (10 Replies)
Discussion started by: vivek d r
10 Replies

7. Shell Programming and Scripting

Using sed in ksh to find and replace string

Hi All, I have a file in which contains location of various data files. I want to change locations using sed. Find and replace strings are in a separate file. Content of this file (/tmp/tt) - /dd/pp/test/test/1/ /pp/aa/test/dg1/ /dd/pp/test/test/2/ /pp/aa/test/dg2/ /dd/pp/test/test/3/... (2 Replies)
Discussion started by: pandeyra
2 Replies

8. Shell Programming and Scripting

QUESTION1: grep only exact string. QUESTION2: find and replace only exact value with sed

QUESTION1: How do you grep only an exact string. I am using Solaris10 and do not have any GNU products installed. Contents of car.txt CAR1_KEY0 CAR1_KEY1 CAR2_KEY0 CAR2_KEY1 CAR1_KEY10 CURRENT COMMAND LINE: WHERE VARIABLE CAR_NUMBER=1 AND KEY_NUMBER=1 grep... (1 Reply)
Discussion started by: thibodc
1 Replies

9. Shell Programming and Scripting

replace (sed?) a string in file with multiple lines (string) from variable

Can someone tell me how I can do this? e.g: a=$(echo -e wert trewt ertert ertert ertert erttert erterte rterter tertertert ert) How do i replace the STRING with $a? I try this: sed -i 's/STRING/'"$a"'/g' filename.ext but this don' t work (2 Replies)
Discussion started by: jforce
2 Replies

10. Shell Programming and Scripting

How to find a certain string in a file and replace it with a value from another file using sed/awk?

Hi Everyone, I am new to this forum and new to sed/awk programming too !! I need to find particular string in file1(text file) and replace it with a value from another text file(file2) the file2 has only one line and the value to be replaced with is in the second column. file 1: (assert (=... (21 Replies)
Discussion started by: paramad
21 Replies
Login or Register to Ask a Question