Awk gsub and the mysterious “1”

萝らか妹 提交于 2019-12-14 04:19:25

问题


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'

on the file marks.txt:

1) Amit Physics 80
2) Rahul Maths 90
3) Shyam Biology 87
4) Kedar English 85
5) Hari History 89

I get the following result:

1) Amit Physics 80
2) RHhul MHths 90
3) ShyHm Biology 87
4) KedHr English 85
5) HHri History 89

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?

Thank you in advance!


回答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.



来源:https://stackoverflow.com/questions/52502311/awk-gsub-and-the-mysterious-1

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!