expand value of variable in sed
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Shell > expand value of variable in sed




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    expand value of variable in sed  
Cologne


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-03-04 07:48 AM

Hi there,

How can I expand a variable in sed expression...For eg. I have the
following

sed '/s\/bin\/httpd/bin\/httpd \-f' `$HTTPD_DIR`\/conf\/httpd/ sal >
sal.new

Now the sed expression literally puts the $HTTPD_DIR in sal.new
file...I want it to put the value of $HTTPD_DIR of it in the file...
how can I acheieve that...

Thanks in advance for your help

Cologne





[ Post a follow-up to this message ]



    Re: expand value of variable in sed  
Alan Connor


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-03-04 07:48 AM

On 3 Oct 2004 00:01:56 -0700, Cologne <cologne_2003@yahoo.com>
wrote:


> Hi there,
>
> How can I expand a variable in sed expression...For eg. I have
> the following
>
> sed '/s\/bin\/httpd/bin\/httpd \-f' `$HTTPD_DIR`\/conf\/httpd/\
> sal > sal.new
>
> Now the sed expression literally puts the $HTTPD_DIR in sal.new
> file...I want it to put the value of $HTTPD_DIR of it in the
> file... how can I acheieve that...
>

That isn't going to put anything anywhere. Try following this
general pattern:

sed "s:/dir/dir:/dir${VAR}:" > file

Use double quotes to allow expansion, ":" as a seperater instead
of "/" to make it easier to read and keep track of what's what,
and enclose the variable in curly braces "${VAR}" to make sure
that adjacent characters aren't included in the variable name.


HTH

AC






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 12:21 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register