Search code examples
unixawkcut

How to get second last field from a cut command


I have a set of data as input and need the second last field based on deleimiter. The lines may have different numbers of delimiter. How can I get second last field ?

example input

text,blah,blaah,foo
this,is,another,text,line

expected output

blaah
text

Solution

  • Got a hint from Unix cut except last two tokens and able to figure out the answer :

    cat datafile | rev | cut -d '/' -f 2 | rev