Get last field using awk substr

The Solution to Get last field using awk substr is

Use the fact that awk splits the lines in fields based on a field separator, that you can define. Hence, defining the field separator to / you can say:

awk -F "/" '{print $NF}' input

as NF refers to the number of fields of the current record, printing $NF means printing the last one.

So given a file like this:


This would be the output:

$ awk -F"/" '{print $NF}' file

~ Answered on 2013-07-29 10:25:08

Most Viewed Questions: