using cut command right to left

Hi guys

I have variable that contains a full directory path.

var=/tmp/a/b/c/d

I want to be able to extract different directories in the path right to left while using / as the delimiter.

so for e.g. if in the above example if I want c then I want it to be in the middle of 1st and second / rather than 4th and 5th.
and if I want to extract do then it would be right of the first / .

If possible please post the full command rather than just suggesting a switch to use.

many thanks
ali

echo $var | awk -F/ '{print $(NF-2)}'

NF is the right most field, subtract values from it to move to the left. In this case, subtracting 2 would return 'b'

thanks mate. Issue resolved :slight_smile: