Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a variable in a sed command

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I'm using an input variable in the sed command which gets ignoored. Here is the part of the script that doesn't work.

##############
echo "\nPlease Enter exactly the string that you want to change...\c"

read ans1

sed 's/ $ans1/ALEXGGG/' infile >outfile
#############

If I don't use the variable the string is changed. Please help.
 
$ans1 is being takne as a string literal ...

change the 's in the sed command to "s

e.g. sed 's/ ... command to sed "s/ ...
 
sed 's/ $ans1/ALEXGGG/' infile >outfile

should read:
sed "s/ALEXGGG/$ans1/" infile > outfile

sed "s/what you have in infile/what you want as replacement in outfile/" infile > outfile ***************************************
Party on, dudes!
[cannon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top