Awk gsub和神秘的"1" [英] Awk gsub and the mysterious "1"
问题描述
我认为这是一个更一般的理解问题,但这是我的问题: 如果我在终端中运行以下命令:
I think it is a more general understanding problem but here is my question: If I run the following command in the terminal:
awk'{gsub("a","H")} 1'
在marks.txt文件上:
on the file marks.txt:
1)Amit Physics 80
2)Rahul数学90
3)Shyam Biology 87
4)Kedar英语85
5)Hari History 89
1) Amit Physics 80
2) Rahul Maths 90
3) Shyam Biology 87
4) Kedar English 85
5) Hari History 89
我得到以下结果:
1)Amit Physics 80
2)RHhul MHths 90
3)ShyHm Biology 87
4)KedHr英语85
5)HHri历史89
1) Amit Physics 80
2) RHhul MHths 90
3) ShyHm Biology 87
4) KedHr English 85
5) HHri History 89
但是,如果我运行时不带"1",我什么也没得到.
But if I run it without that "1", I get nothing.
awk'{gsub("a","H")}'
为什么这是如此重要,它代表什么?
Why is this one so important and what does it stand for?
提前谢谢!
推荐答案
Awk适用于默认操作为print $0
的condition { action }
表达式.当您将1
作为条件写入时,这是一个真实条件,因此将调用打印当前记录的默认操作.
Awk works on condition { action }
expressions where the default action is print $0
. When you write 1
as a condition then that is a true condition and so invokes the default action of printing the current record.
这篇关于Awk gsub和神秘的"1"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!