l*j 发帖数: 336 | 1 【 以下文字转载自 Linux 讨论区 】
【 原文由 lxj 所发表 】
初学shell script, 向各位请教,
有一不规则文本文件,中间有多个变量,例如 X1, X2,...
还有值与这些变量有关, 如 1000*X1, 500+X2等,
用空格或TAB分离开,
问题是,如果我知道X1的值,例如X1=3.1415926,
想替换该文件中的X1变量,并且在相应的位置上算出表达式的值,
如1000*X1的地方,就用3141.5926代替,等等,
我用 cat sourcefile | sed 's/X1/3.1415926/g' 可以替换
所有的X1,但是,不知道怎么expr,而且放在原来的位置上。 :)
请指教, |
|