[colug-432] Printing Last Field

Rick Hornsby richardjhornsby at gmail.com
Wed Oct 14 18:46:20 EDT 2015


> On Oct 14, 2015, at 16:59, jep200404 at columbus.rr.com wrote:
> 
> Compare the two following filter chains for printing the last field on a line.
> Which one would you choose? Why?
> 
>    ... | rev | awk '{print $1}' | rev
>    ... | awk '{print $NF}'

I have used the double reverse trick before in some situations - mostly in combination with cut as opposed to awk.  In comparison terms, I find the double rev a little bit messy and a little bit less readable than the second option.

The second option achieves the same end in a more concise and compact manner most importantly --> without obscuring/obfuscating the behavior or effect.


More information about the colug-432 mailing list