Search code examples
shellunixawkhp-ux

awk's END block behaviour on HP-UX


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.


Solution

  • 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 :)