Anyone know how to use cut to select the last, or second to last, or a range from the
end of the line using a delimiter?
cut -d: -f 1 will pull out the first, cut -d: -f 1-3 will get 1 to 3, but only from the beginning. Is it possible to chomp away from the end?
I have lines of different lengths and all I want is the last item (so it's not possible to grab a specified field number, as sometimes the last one is field3 others it's 5 or 8 or more.
Ex.
Code:
item1:item2:item3:item4
item1:item2
item1:item2:item3:item4:item5:item6:item7:item8
so I want line1, item4; line2,item2, line3,item8 etc.
Right now I'm munging it with a python script, but I figure cut must be able to do this more simply?
Any ideas?