@~$ echo "abc:cde:efg" | awk 'BEGIN {FS=":"} {print $NF}'
efg

The variable NF holds the number or records in the string, which is 3 in this case. So when you’re do a print $NF, you are actually executing print $3, and thus printing the last record/substring.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

You May Also Like

Error While Parsing Json using Python – TypeError: list indices must be integers, not str

Jotting this down for fellow googlers. I recently started learning a bit…