Sed cannot handle variables

this is the content of my sh file:

for file in *.html
do
aa=`grep -o "<div id\=\"vdl.*" $file `
bb=`grep -o "<a href\=\"inde.*<\/a>"  $file `
sed -i "s/$aa/$bb/g"  $file
done

execute: bash-x. / 1.sh
the result is as follows

+ for file in *.html
PP grep -o "<div id\=\"vdl.*" 10621997.html
+ aa="<div id="vdl"><script>show_vdl();</script> </div><div id="vfmt"><script>show_vfmt();</script> </div><div id="vf1"><script>show_vf1();</script></div><div id="vf2"><script>show_vf2();</script></div><div id="footlink"><a href="10621996.html"></a>  <a href="/ "
PP grep -o "<a href\=\"inde.*<\/a>" 10621997.html
+ bb="<a href="index.html"></a></div><div id="linkright"><a href="10621996.html"></a> |   | <a href="10621998.html"></a>"
+ sed -i "s <div id="vdl"><script>show_vdl();</script> </div><div id="vfmt"><script>show_vfmt();</script> </div><div id="vf1"><script>show_vf1();</script></div><div id="vf2"><script>show_vf2();</script></div><div id="footlink"><a href="10621996.html"></a>  <a href="/  <a href="index.html"></a></div><div id="linkright"><a href="10621996.html"></a> |   | <a href="10621998.html"></a>  10621997.html"
sed:-e  -sharp1 46:"s" 
+ for file in *.html
PP grep -o "<div id\=\"vdl.*" 10621998.html
+ aa="<div id="vdl"><script>show_vdl();</script> </div><div id="vfmt"><script>show_vfmt();</script> </div><div id="vf1"><script>show_vf1();</script></div><div id="vf2"><script>show_vf2();</script></div><div id="footlink"><a href="10621997.html"></a>  <a href="/ "
PP grep -o "<a href\=\"inde.*<\/a>" 10621998.html
+ bb="<a href="index.html"></a></div><div id="linkright"><a href="10621997.html"></a> |   | <a href="10621999.html"></a>"
+ sed -i "s <div id="vdl"><script>show_vdl();</script> </div><div id="vfmt"><script>show_vfmt();</script> </div><div id="vf1"><script>show_vf1();</script></div><div id="vf2"><script>show_vf2();</script></div><div id="footlink"><a href="10621997.html"></a>  <a href="/  <a href="index.html"></a></div><div id="linkright"><a href="10621997.html"></a> |   | <a href="10621999.html"></a>  10621998.html"
sed:-e  -sharp1 46:"s" 

ask for advice on how to change it, thank you.

Feb.19,2022

sed -i "s|$aa|$bb|g"  $file

try this


I estimate that a sed command can only handle a single line of content, not two lines
, so I took a different approach and solved it.

for file in *.html
do
grep -o  '<a href\=\"inde.*<\/a>'  $file  > /tmp/linshi
sed  -i -e '/<div id\=\"vdl/r /tmp/linshi'  -e '/<div id\=\"vdl/d'  $file
done

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1c1c698-332d3.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1c1c698-332d3.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?