Solved

A very very simple script

Posted on 2006-11-02
1
256 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
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

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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

809 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