例子:
jon@jontest:~$ echo "34523" > done.txt # write value to file
jon@jontest:~$ val=`cat done.txt` # read into a variable $val
jon@jontest:~$ #create infile.sql with some sample data
jon@jontest:~$ printf "aaaaa\nbbbbb?\n?ccccc\ndd?ddd\ne?ee?ee\n" > infile.sql
jon@jontest:~$ sed "s/\?/$val/g" infile.sql > outfile.sql
jon@jontest:~$ cat infile.sql
aaaaa
bbbbb?
?ccccc
dd?ddd
e?ee?ee
jon@jontest:~$ cat outfile.sql
aaaaa
bbbbb34523
34523ccccc
dd34523ddd
e34523ee34523ee
给 sed的g
s 表达式末尾的意思是全局的,它将确保您替换所有出现的?
sed 执行替换的每一行。
与您的参数一致:
var=`cat done.txt`; sed "s/\?/$var/g" CreateView.sql > CreateViewFinal.sql