0
改变特定位置的字符我有我想以编程方式改变设置不同的参数文件:如何使用shell变量
$ cat ex.dat
line 1
here's another line
this is the number I want to change --> 1e-11
more lines
我想改变1e-11
的价值观5.
,10
和20.
。类似这样的:
mkd()
{
mkdir $1;
cd $1
}
for j in 1 2 3 4 5 ; do
mkd WS$j
cp ../ex.dat .
sed -ie '3s/1e-11/${j}./' ex.dat
cd ..
done
我的方法不起作用。我如何将1e-11
替换为$j
的值?
$ cat WS3/ex.dat
line 1
here's another line
this is the number I want to change --> ${j}.
more lines
你是什么意思*“不工作”*?解释具体行为对其他人有帮助...... –
_Double-quote_'sed'脚本确保'$ {j}'被shell扩展。 '-ie'也会创建一个后缀为'e'的备份文件,也许你打算使用'-i -e',或者简单地使用'-i'。另外,一般情况下双引号所有shell变量引用,以防止不必要的修改。 – mklement0