Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does this awk scripts do?

Tags:

makefile

awk

I found this in a embedded in a Makefile:

awk '/@/{print "  \"" $$_ "\\n\"" }' file

I know the prototype of awk is:

awk 'pattern {action}' file

But what does @ and $$_ mean?

like image 489
compile-fan Avatar asked Dec 31 '25 12:12

compile-fan


1 Answers

It looks like the underscore character is simply a variable in this case. And since it is not initialized, it has the value of zero. Thus, $_ is equivalent to $0, which refers to the entire line that was processed. I think that it could also have been written $x since x would be an uninitialized variable.

Since it appears in a makefile, two dollar signs are needed (it is a special character in a makefile) to produce a single dollar sign in the command.

And as already mentioned by Nemo, the @ is simply the pattern. Any line containing @ would be matched.

like image 176
Mark Wilkins Avatar answered Jan 05 '26 06:01

Mark Wilkins



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!