Solved

replacing text with text

Posted on 1998-12-10
4
227 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 84

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 84

Accepted Solution

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this tutorial I will explain how to make squid prevent malwares in five easy steps: Squid is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

932 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now