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
To look at the last few lines of a file, use the tail command. tail works the same way as head: type tail and the filename to see the last 10 lines of that file, or type tail -number filename to see the last number lines of the file.
Use the tail command to write the file specified by the File parameter to standard output beginning at a specified point. This displays the last 10 lines of the accounts file. The tail command continues to display lines as they are added to the accounts file.
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
Awk is suited well for this:
awk -F, '{print $(NF-1)}' file
The variable NF is a special awk variable that contains the number of fields in the current record.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With