Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

replacing text with text

Posted on 1998-12-10
4
Medium Priority
?
235 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 800 total points
ID: 1638799
"" to allow shell variable expansion,
s||| (or other unused character) to allow / inside of the expression
0

Featured Post

Basic Security of Your VPC

So, you’ve got this shiny new VPC and a fancy new application configured on your EC2 servers ready to go. This application is only accessible from your computer, which is great for security, but you need your users to be able to access it! So, what’s the easiest way to do this?

Question has a verified solution.

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

Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
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.
Suggested Courses

719 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