sed command help

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

sed command help

Manoj
Hi all,
I have a file like below
vi a.txt
properties="-Dconnection=${MBS_CONNECT} -Dpdffilename=$pdf_output_file -Djrxmlfilename=$full_path -Djob=$job -Dsessid=${MBS_SESSION_
ID} -Dlog=${MBS_WRK}/$phase/log -Duname=${LOGNAME} -DRELEASE=${MBS_RELEASE} -DSEQUENCE=? -Dename=${MBS_ENVIRONMENT}"

I need to write a script which will replace the ? after the -DSEQUENCE= with a value which is stored in a variable say $b.
After running the script my file should be changed to
b=10
properties="-Dconnection=${MBS_CONNECT} -Dpdffilename=$pdf_output_file -Djrxmlfilename=$full_path -Djob=$job -Dsessid=${MBS_SESSION_
ID} -Dlog=${MBS_WRK}/$phase/log -Duname=${LOGNAME} -DRELEASE=${MBS_RELEASE} -DSEQUENCE=10 -Dename=${MBS_ENVIRONMENT}"

I will be grateful if anyone helps me on this.

Reply | Threaded
Open this post in threaded view
|

Re: sed command help

Guru
Administrator
Hi Manoj

  Did you want something like this:


$ b=23

$ cat file
properties="-Dconnection=${MBS_CONNECT} -Dpdffilename=$pdf_output_file -Djrxmlfilename=$full_path -Djob=$job -Dsessid=${MBS_SESSION_
ID} -Dlog=${MBS_WRK}/$phase/log -Duname=${LOGNAME} -DRELEASE=${MBS_RELEASE} -DSEQUENCE=10 -Dename=${MBS_ENVIRONMENT}"

$ sed "s/SEQUENCE=\([^ ]*\)/SEQUENCE=$b/" file
properties="-Dconnection=${MBS_CONNECT} -Dpdffilename=$pdf_output_file -Djrxmlfilename=$full_path -Djob=$job -Dsessid=${MBS_SESSION_
ID} -Dlog=${MBS_WRK}/$phase/log -Duname=${LOGNAME} -DRELEASE=${MBS_RELEASE} -DSEQUENCE=23 -Dename=${MBS_ENVIRONMENT}"

 b contains the value 23. the sed command replaces the value.

Guru.
Reply | Threaded
Open this post in threaded view
|

Re: sed command help

Manoj
Thanks Guru. That was what I wanted exactly.