开发者

Does awk print all if field variable doesn't exist?

I am trying to understand some scripts that I have inherited and make use of awk. In one of the scripts are these lines:

report=`<make call to Java class that generates 开发者_如何学编程a report`
report=`echo $report|awk '{print $5}'`

The report generated in line 1 has data like this:

ABC1234:0123456789:ABCDE
ABC4321:9876543210:EDCBA
...

The awk generated report is the same as the original one.

There is no 5th field in the report since there is no whitespace and a different field separator has not been defined. I know that using $0 will return all fields. Does specifying a field that doesn't exist do the same?


No:

echo "1 2 3"|awk '{print $5}'

The above prints nothing. Don't know why it is behaving like you are specifying. If you were to use " instead of ', then it would print because $5 would be expanded by shell, but as written it should not.


Something is wrong with your test.

The expected awk behavior in this case is to print a blank line for each input line, and that's what I see when I run with either the 1TA or gawk.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜