为什么"1"在awk中打​​印当前行? [英] Why does "1" in awk print the current line?

查看:74
本文介绍了为什么"1"在awk中打​​印当前行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此答案

awk '$2=="no"{$3="N/A"}1' file

被接受.注意AWK脚本末尾的1.在评论中,答案的作者说

was accepted. Note the 1 at the end of the AWK script. In the comments, the author of the answer said

[1是]显示当前行的一种神秘方式.

[1 is] a cryptic way to display the current line.

我很困惑.怎么运作的?

I'm puzzled. How does that work?

推荐答案

awk

由于1始终求值为 true ,因此它将执行默认操作{print $0},因此打印存储在$0

Since 1 always evaluates to true, it performs default operation {print $0}, hence prints the current line stored in $0

因此,awk '$2=="no"{$3="N/A"}1' file等效于

awk '$2=="no"{$3="N/A"} {print $0}' file

再次$0 print 的默认参数,因此您也可以编写

Again $0 is default argument to print, so you could also write

awk '$2=="no"{$3="N/A"} {print}' file


实际上,您也可以使用任何非零数字或始终评估为 true 的任何条件代替 1


In-fact you could also use any non-zero number or any condition which always evaluates to true in place of 1

这篇关于为什么"1"在awk中打​​印当前行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆