I have a path as a string in a shell-script, could be absolute or relative:
/usr/userName/config.cfg
or
../config.cfg
I want to extract the file name (part after the last /, so in this case: ‘config.cfg’)
I figure the best way to do this is with some simple regex? Is this correct? Should or should I use sed or awk instead?
Shell-scripting’s string manipulation features seem pretty primative by themselves, and appear very esoteric.
Any example solutions are also appreciated.
Instead of string manipulation I’d just use
Edit:
Thanks to unwind for some newer syntax for this (which assumes your filename is held in $filename):