How to append something to a word using sed command

Hi,
How to append something to already existing word.
Suppose, I have the following line as a part of a file.

VVV= jdbc: oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=)(PORT=XXXX))(ADDRESS=(PROTOCOL=TCP)(HOST=)(PORT=XXXX))(LOAD_BALANCE=yes)(PROGRAM_NAME=SOME_PROGRAM_NAME)(CONNECT_DATA=(SERVER=DEDICATED)))

Now I want to change the value of the PROGRAM_NAME as SOME_PROGRAM_NAME_VERY_USEFUL.

That is, I want to append something to which is already existing using sed command.
This PROGRAM_NAME can be anywhere in that line, i.e., not in a specific field number.
And the value of the PROGRAM_NAME may vary depending on the server in which we are using.

Please help me in this...:wall:

$ sed "s/PROGRAM_NAME=[^)]*/PROGRAM_NAME=put what you want here/" file
VVV= jdbc: oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=)(PORT=XXXX))(ADDRESS=(PROTOCOL=TCP)(HOST=)(P ORT=XXXX))(LOAD_BALANCE=yes)(PROGRAM_NAME=put what you want here)(CONNECT_DATA=(SERVER=DEDICATED)))

Hi Scottn,
Thanks for ur very quick reply...

is the original value.
But What I want exactly is,
The original value should be as same as before. But also some more content should be appended to it. So for that I hope it should recognize the first ) after PROGRAM_NAME=... and then append _VERY_USEFUL to that before that first occurance of the ).
And the value of the PROGRAM_NAME may vary depending on the server in which we are using.
Hope you got my question now.

Also I want to make the changes permanent in the modifying file.
Please help me...

Ah, sorry. Misread :slight_smile:

$ sed "s/PROGRAM_NAME=[^)]*/&_put_what_you_want_here/" file
VVV= jdbc: oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=)(PORT=XXXX))(ADDRESS=(PROTOCOL=TCP)(HOST=)(P ORT=XXXX))(LOAD_BALANCE=yes)(PROGRAM_NAME=SOME_PROGRAM_NAME_put_what_you_want_here)(CONNECT_DATA=(SERVER=DEDICATED)))

If you want to make it permanent, use sed -i if it's supported, otherwise write to a temporary file, and then copy the new file over the original.

Ah....That's So nice of you..It worked for me... :slight_smile:
Can you also help me how can I insert a variable value or a command output into that....
Say for example, i want to append the output of the `dnsdomainname` command to the PROGRAM_NAME.
When I am trying for this, the $ value if variable, or the command name itself is being reflecting there... :frowning:

Would this not do?

sed "s/PROGRAM_NAME=[^)]*/&_$(dnsdomainname)/" file

(although, if I understand what you want, you already answered the question with `dnsdomainname`, but I prefer the $(...) notation over the back-quotes!)

Hi,
The above thing is not working for me... :frowning: