如何在foreach循环中正确使用sed

时间:2018-08-27 06:25:00

标签: bash shell

如何在sed循环中正确使用for?我想遍历一个数组,每个循环,打开一个文件template.txt,进行弹簧更换并将结果输出到一个文件。例如:

values=( "val_1982" "val_1985" "val_1987" )

for i in "${values[@]}"
do 
    sed -e "s/\${VAL_ID}/$i/" \
    -e "s/\${ENTRY}/"local"/" template.txt > outputfile_$i.txt
done

但是我得到了

bash: template.txt: command not found
bash: template.txt: command not found
bash: template.txt: command not found

已创建输出文件,但全部为空。

1 个答案:

答案 0 :(得分:0)

我替换了它,它起作用了:

for i in val_1982 val_1985 val_1987
do 
    sed -e "s/\${VAL_ID}/$i/" \
    -e "s/\${ENTRY}/"local"/" template.txt > outputfile_$i.txt
done
相关问题