How to split string on forward slash in bash

Also awk – use slash as separator and print last field

echo "/gas/string" | awk -F/ '{print $NF}'

Or cut – but that will only work if you have same number of directories to strip

echo "/gasg/string" |cut -d/ -f 3

Leave a Comment