• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 268
  • Last Modified:

replacing text with text

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
Soth
Asked:
Soth
  • 2
  • 2
1 Solution
 
SothAuthor Commented:
my scripts use #!/bin/sh

0
 
ozoCommented:
sed "s|$base_dir|$install_dir|g"  myfile1 >myfile2
0
 
SothAuthor Commented:
you are a god damn genius
answer and recieve your prize

0
 
ozoCommented:
"" to allow shell variable expansion,
s||| (or other unused character) to allow / inside of the expression
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now