在HP-UX awk的END块行为 [英] awk's END block behaviour on HP-UX

查看:168
本文介绍了在HP-UX awk的END块行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么的awk'END {}打印文件返回一个空字符串?

Why does awk 'END{print}' file return an empty string?

我检查的文件,它不空行结束。

I've checked the file and it does not end with empty line.

我在HP-UX。

推荐答案

END 表示以后该文件已被处​​理执行给定块,有没有数据打印已与其关联。

END means "execute the given block after the file has been processed", there is no data to print associated to it.

如果你要处理的最后一行,保存每一行中的缺省块一个变量,然后在处理结束块中的变量。

If you want to process the last line, save each line in a variable in a default block and then process the variable in the end block.

awk '{ last_line = $0; } END { /* do something with last_line */}' file

或者使用把数据输入 AWK 前:)

这篇关于在HP-UX awk的END块行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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