Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

replacing text with text

Posted on 1998-12-10
4
Medium Priority
?
241 Views
Last Modified: 2010-04-20
I have 2 variables in a script
$base_dir
$install_dir

I have a file with output like this:
/home/matt/1
/home/matt/2
/home/matt/3
/home/matt/5

/home/matt is stored in $base_dir which
does not necessarily have to hold /home/matt.

I want to replace /home/matt with the contents of $install_dir

Using sed i thought it would look like this:
sed 's/$base_dir/$install_dir/g' myfile1 >myfile2

but it doesn't work. (i don't think sed accepts variables)

How can it be done??
0
Comment
Question by:Soth
  • 2
  • 2
4 Comments
 

Author Comment

by:Soth
ID: 1638796
my scripts use #!/bin/sh

0
 
LVL 85

Expert Comment

by:ozo
ID: 1638797
sed "s|$base_dir|$install_dir|g"  myfile1 >myfile2
0
 

Author Comment

by:Soth
ID: 1638798
you are a god damn genius
answer and recieve your prize

0
 
LVL 85

Accepted Solution

by:
ozo earned 800 total points
ID: 1638799
"" to allow shell variable expansion,
s||| (or other unused character) to allow / inside of the expression
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
This article will show you step-by-step instructions to build your own NTP CentOS server.  The network diagram shows the best practice to setup the NTP server farm for redundancy.  This article also serves as your NTP server documentation.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month6 days, 13 hours left to enroll

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question