这个awk脚本做什么? [英] What does this awk scripts do?

查看:70
本文介绍了这个awk脚本做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Makefile的嵌入式文件中找到了它:

I found this in a embedded in a Makefile:

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

我知道awk的原型是:

I know the prototype of awk is:

awk 'pattern {action}' file

但是@$$_是什么意思?

推荐答案

在这种情况下,下划线字符似乎只是一个变量.并且由于未初始化,因此其值为零.因此,$_等效于$0,它表示已处理的整个行.我认为它也可能被写为$x,因为x将是一个未初始化的变量.

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.

由于它出现在makefile中,因此需要两个美元符号(makefile中的特殊字符)才能在命令中生成一个美元符号.

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.

正如Nemo所提到的,@只是模式.包含@的任何行都将被匹配.

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

这篇关于这个awk脚本做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆