sed 变量替换

20.5.101.31_/root>cat aaa
111"
222"
333"

20.5.101.31_/root>cat a2.sh
for ((i=1;i<=117;i++));
do
 echo "sed -i '10s/"$/" $i.txt/' aaa" | sed "s/10s/${i}s/"
done

20.5.101.31_/root>sh ./a2.sh
sed -i '1s/"$/" 1.txt/' aaa
sed -i '2s/"$/" 2.txt/' aaa
sed -i '3s/"$/" 3.txt/' aaa


20.5.101.31_/root>cat aaa
111"
222"
333"

20.5.101.31_/root>cat t1.sh
sed -i '1s/"$/" 1.txt/' aaa
sed -i '2s/"$/" 2.txt/' aaa
sed -i '3s/"$/" 3.txt/' aaa
20.5.101.31_/root>sh ./t1.sh
20.5.101.31_/root>cat aaa
111" 1.txt
222" 2.txt
333" 3.txt

20.5.101.31_/root>cat a2.sh
for ((i=1;i<=117;i++));
do
 #echo "sed -i '10s/"$/" $i.txt/' aaa" | sed "s/10s/${i}s/"
 sed -i "${i}s/"$/" $i.txt/" aaa
done
20.5.101.31_/root>cat aaa
111"
222"
333"

20.5.101.31_/root>sh ./a2.sh
20.5.101.31_/root>cat aaa
111" 1.txt
222" 2.txt
333" 3.txt
原文地址:https://www.cnblogs.com/hzcya1995/p/13349147.html