What does the semicolon mean in awk action?

I am trying to decipher the action in the following awk expression, in particular about what it means ; after the first user-defined variable is specified.

 { num_gold++; wt_gold += $2 } 
+6
source share
1 answer

In awk you can write two statements on the same line, separated by a character ; (semi-colon)

 { num_gold++; wt_gold += $2 } 

Otherwise, you should put them on separate lines:

 { num_gold++ wt_gold += $2 } 

To print variables, simply add print before the variables:

 { num_gold++ wt_gold += $2 print num_gold print wt_gold } 

As I said, you can put them all on one line:

 { num_gold++; wt_gold += $2; print num_gold; print wt_gold; } 

Too long!

print also takes several arguments, so try print num_gold, wt_gold .

+4
source

Source: https://habr.com/ru/post/918334/


All Articles