awk's END block behaviour on HP-UX

后端 未结 2 1040
Happy的楠姐
Happy的楠姐 2020-12-07 05:07

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

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

I\'m on HP-UX.

2条回答
  •  醉话见心
    2020-12-07 05:34

    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
    

    Or use tail before feeding data to awk :)

提交回复
热议问题