问题
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