Unix Shell - expand value of variable in sed

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > October 2004 > expand value of variable in sed





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author expand value of variable in sed
Cologne

2004-10-03, 2: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
Alan Connor

2004-10-03, 2: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

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com