View Full Version : bash variables within sed commands not working!
Mlehliw
March 4th, 2008, 06:23 PM
I'm trying to do a replacement with sed inside a bash script. My sed command looks something like the following
sed "s/TEXT/$VAR/" input_file
But sed keeps complaining at me about the $ character. Is it possible to put a variable inside sed in this manner?
kaens
March 4th, 2008, 07:55 PM
$ cat >> test << EOF
this is a test
Ctrl-D
$ VAR=test
$ sed s/$VAR/toast/ test
this is a toast
Works with $VAR in replacement or searching position. What are you trying to expand $VAR to? What happens when you do the small example above?
ghostdog74
March 4th, 2008, 10:17 PM
show your code
Ramses de Norre
March 5th, 2008, 08:05 AM
sed "s/TEXT/$VAR/" input_file
sed -e s/TEXT/$VAR/ input_file
Mlehliw
March 15th, 2008, 12:47 PM
I came up with a solution and completely forgot about this thread, anyway if anyone's having the same problems. I changed
sed "s/TEXT/$VAR/" input_file
to
sed "s|TEXT|$VAR|" input_file
vBulletin® v3.8.7, Copyright ©2000-2012, vBulletin Solutions, Inc.