SoundTheSurrender
Diamond Member
I'm trying to use the sed command in unix with variables. It takes my input but doesn't export the changes over. Obviously I have to get rid of the slashes but everything I've tried doesn't work. Does SED only work with manually enter words to look for and change? I need it to use variables. If that's not possible, what would be the best way to go about this?
#! /bin/csh
# Check to make sure the testfile exists
set list="testfile"
if ( -e $list) then
echo $list exists
else
echo $list does not exit
endif
# End Check to make sure the testfile exists
# Read each mispelled word
foreach name (`ispell -l < testfile`)
echo "'$name' is mispelled."
#Correct it
echo Correct the spelling
set name1 = $<
echo Name $name
# The echo command above and below just check to see if variables exist
echo Name1 $name1
# Replace the word inputted in name1 with the incorrect spelling of name
#sed -e 's/$name1/$name/g' < testfile > testfile.tmp
sed -e 's/$name/$name1/g' < testfile > testfile.tmp
/****** testfile
The dog is deadd
#! /bin/csh
# Check to make sure the testfile exists
set list="testfile"
if ( -e $list) then
echo $list exists
else
echo $list does not exit
endif
# End Check to make sure the testfile exists
# Read each mispelled word
foreach name (`ispell -l < testfile`)
echo "'$name' is mispelled."
#Correct it
echo Correct the spelling
set name1 = $<
echo Name $name
# The echo command above and below just check to see if variables exist
echo Name1 $name1
# Replace the word inputted in name1 with the incorrect spelling of name
#sed -e 's/$name1/$name/g' < testfile > testfile.tmp
sed -e 's/$name/$name1/g' < testfile > testfile.tmp
/****** testfile
The dog is deadd