Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the semicolon represent in an awk action?

Tags:

linux

awk

I'm attempting to decipher the action in the following awk statement specifically what the ; after the first user defined variable refers to.

{ num_gold++; wt_gold += $2 }
like image 405
PeanutsMonkey Avatar asked Jun 18 '12 07:06

PeanutsMonkey


1 Answers

In awk, you can write two statements in one line separated by ;(semi-colon)

{ num_gold++; wt_gold += $2 }

Otherwize, you should put them into separated lines:

{
    num_gold++
    wt_gold += $2
}

To print the variables, you just add print before the variables:

{
    num_gold++
    wt_gold += $2

    print num_gold
    print wt_gold
}

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

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

It's too long!

print also accepts multiple arguments, so try print num_gold, wt_gold.

like image 121
kev Avatar answered Nov 15 '22 03:11

kev