Solved it using awk :
echo "/dir0/dir1/dir2/filename.ext" | awk -F'/' '{print $(NF-1)}'
The output of above will be:
dir2
Solved it using awk :
echo "/dir0/dir1/dir2/filename.ext" | awk -F'/' '{print $(NF-1)}'
The output of above will be:
dir2