How to append something to a word using sed command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to append something to a word using sed command
# 1  
Old 07-18-2011
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.
Code:
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...Smilie
# 2  
Old 07-18-2011
Code:
$ 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)))

# 3  
Old 07-18-2011
Hi Scottn,
Thanks for ur very quick reply...
Quote:
PROGRAM_NAME=SOME_PROGRAM_NAME
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...
# 4  
Old 07-18-2011
Ah, sorry. Misread Smilie

Code:
$ 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.
# 5  
Old 07-18-2011
Ah....That's So nice of you..It worked for me... Smilie
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... Smilie
# 6  
Old 07-18-2011
Would this not do?
Code:
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!)
# 7  
Old 07-26-2011
Hi,
The above thing is not working for me... Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command to append word at end of line

hello Team, I am looking for sed command or script which will append word at end of line. for example. I want to validate particular filesystem with mount |<filesystem name> command. if nodev parameter is not there then it should add in the fstab file with receptive to the filesystem. # mount... (8 Replies)
Discussion started by: ghpradeep
8 Replies

2. UNIX for Beginners Questions & Answers

Getting error in sed command in replacing a word in all xmls

Hi Folks , I have to replace the following value in all the xml files so the value is tcp://pondevpms1.fm.rbsgrp.net:6033,pondevpms2.fm.rbsgrp.net:6033 and the value with it need to be replaces is shown below tcp://pondevpms1:3063 so i have fired the below command inside... (3 Replies)
Discussion started by: unclesamm
3 Replies

3. Shell Programming and Scripting

How to append a value to the output after using sed command?

Hi All, I have a file where I am converting newlines to comma separated values but I would like to append zero if the output is empty Here is the command I am using sed -n -e 'H;${x;s/\n/,/g;s/^,//;p;}' test1.txt test1.txt will have comma seperated values but sometimes this file can be... (6 Replies)
Discussion started by: rajeevm
6 Replies

4. Shell Programming and Scripting

How to use variables in 'sed' append command?

HELLO!! I'm trying to pass a variable with in the 'sed' command (which would add some piece of code to file at a particular line). We can use sed '{line-number}a\ alfjaljf\ aslfjsfsjafl\ adlfjaf\' file.txt If file.txt is Now, I would like to add the parameter 'lmn' after... (1 Reply)
Discussion started by: mjavalkar
1 Replies

5. Shell Programming and Scripting

sed command to remove a word from string

Hello All, I am running a command find . -name amp.cfg | cut -c 3- which gives me output something like below rel/prod/amp.cfg rel/fld/amp.cfg deb/detail/amp.cfg deb/err/amp.cfg I want to remove trailing "/amp.cfg" so that i should get output something like... (7 Replies)
Discussion started by: anand.shah
7 Replies

6. Shell Programming and Scripting

sed command to replace a word with new line and /

Hi, I have been trying to replace the key word "SQL> spool off " with "/ show errors" with out double quotes in all the files in a directory. above show erros should be displayed next line Could you please help me how to do that. I have tried something like this... (3 Replies)
Discussion started by: pointers
3 Replies

7. Shell Programming and Scripting

awk or sed command to print specific string between word and blank space

My source is on each line 98.194.245.255 - - "GET /disp0201.php?poc=4060&roc=1&ps=R&ooc=13&mjv=6&mov=5&rel=5&bod=155&oxi=2&omj=5&ozn=1&dav=20&cd=&daz=&drc=&mo=&sid=&lang=EN&loc=JPN HTTP/1.1" 302 - "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.0.3705; .NET CLR... (5 Replies)
Discussion started by: elamurugu
5 Replies

8. Shell Programming and Scripting

Sed : identify a pattern and append a word at the end of a line

Hello to all, On aix, I want to identify a term on a line in a file and then add a word at the end of the line identified. I do not want the word to be added when the line contains the symbol "#". I use the following command, but it deletes the term identified then adds the word. #sed... (4 Replies)
Discussion started by: dantares
4 Replies

9. Shell Programming and Scripting

What's wrong with this sed command? delete & append

I want to write a sed command that does the following work: file: <a>asdfasdf<\s> <line>hello</line> <b>adf<\c> <b>tttttttt<\c> output: name=hello sed -e 's/^*//' -n -e '/<line>/s/<*>//gp;' -e 's/^/name="/g' file but I can not append "=" after getting the line with... (5 Replies)
Discussion started by: minifish
5 Replies

10. UNIX for Dummies Questions & Answers

append word to lines

Hi all, Can someone suggest how to append some word to all lines in file. for example word "Honey" to file f1 with lines: Mia Katrin Elizabeth to get Honey Mia Honey Katrin Honey Elizabeth Thanks in advance Givi (3 Replies)
Discussion started by: giviut
3 Replies
Login or Register to Ask a Question