Bash 如果第一列匹配,则处理第二列

Bash 如果第一列匹配,则处理第二列,bash,awk,Bash,Awk,如果第一列与我定义的参数匹配,我只希望第二列乘以exp(3) cat inputfile.i 100 2 200 3 300 1 100 5 200 2 300 3 我希望输出为: 100 2 200 60.25 300 1 100 5 200 40.17 300 3 我尝试了以下代码: awk ' $1 == "200" {print $2*exp(3)}' inputfile 但是实际上没有显示任何内容您没有打印不匹配的行,您不需要引用数字 $ awk '$1==200{$2

如果第一列与我定义的参数匹配,我只希望第二列乘以exp(3)

cat inputfile.i

100 2
200 3
300 1


100 5
200 2
300 3
我希望输出为:

100 2
200 60.25
300 1

100 5
200 40.17
300 3
我尝试了以下代码:

awk ' $1 == "200" {print $2*exp(3)}'  inputfile 

但是实际上没有显示任何内容

您没有打印不匹配的行,您不需要引用数字

$ awk '$1==200{$2*=exp(3)}1' file

100 2
200 60.2566
300 1


100 5
200 40.1711
300 3

您没有打印不匹配的行,您不需要引用数字

$ awk '$1==200{$2*=exp(3)}1' file

100 2
200 60.2566
300 1


100 5
200 40.1711
300 3

inputfile.i和inputfile之间有区别吗

无论如何,我给你的解决方案是:

awk '$1 == 200 {printf "%s %.2f\n",$1,$2*exp(3)};$1 != 200 {print $0}'  inputfile.i
100 2
200 60.26
300 1


100 5
200 40.17
300 3

inputfile.i和inputfile之间有区别吗

无论如何,我给你的解决方案是:

awk '$1 == 200 {printf "%s %.2f\n",$1,$2*exp(3)};$1 != 200 {print $0}'  inputfile.i
100 2
200 60.26
300 1


100 5
200 40.17
300 3