[英]Find and Replace with parameter in Linux
我有许多文件包含这样的行:
_str = floatNumber_ (including spaces)
我想将该浮点数乘以一个常数,并得到如下结果:
_str = 4xfloatNumber_
怎么做?
您可以使用awk
做到这一点:
awk 'BEGIN{FS="="};{print $1 "= " 4*$2}' < src_file > dest_file
细节:
BEGIN{FS="="}
:define =
作为字段分隔符, {print $1 "= " 4*$2}
进行所需的操作, < src_file
:从src_file
读取数据, > dest_file
:将数据写入dest_file
。 并且如果您有几个文件要处理:
# where *.* are the files you want to process
for i in *.*
do
awk 'BEGIN{FS="="};{print $1 "= " 4*$2}' < $i > $i.out
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.