Solved

A very very simple script

Posted on 2006-11-02
1
259 Views
Last Modified: 2012-05-05
Hi All ,

 Just a simple script . Trying to read 2 variables from user. And then replace the occurance of the  first variable with the second one in a particular file /tmp/test.

 But somehow (i guess so) the sed is not able to read the contents of a variable. ie. $orig and $name values.

 Should be matter of some extra characters to be used in sed . Plz help.

Script :-

 
 #!/bin/bash
 echo "Put original word"
 read orig
 echo " Put your name "
 read name
 cat /tmp/test | sed 's/$orig/$name/' > /tmp/test
 tail /tmp/test/  -n 1

 

0
Comment
Question by:harmsingh
[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
1 Comment
 
LVL 45

Accepted Solution

by:
sunnycoder earned 20 total points
ID: 17864229
Hi harmsingh,

Use double quotes instead of single quotes ... Variables are read by shell and shell does not "peek" into anything enclosed in single quotes

sed "s/$orig/$name/"

Cheers!
sunnycoder
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Trying to install MonoDevelop from sourde on Ubuntu 14.04 trusty 10 629
pipe to sed or perl, please help 5 145
Problem to telnet 23 167
what does "puppet agent -t" do ? 2 359
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

752 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