bash to get file name
fspec="/exp/home1/abc.txt" filename="${fspec##*/}" # get filename dirname="${fspec%/*}" # get directory/path name
other ways
awk
$ echo $fspec | awk -F"/" '{print $NF}' abc.txt
sed
$ echo $fspec | sed 's/.*///' abc.txt
using IFS
$ IFS="/" $ set -- $fspec $ eval echo ${${#@}} abc.txt
https://stackoverflow.com/questions/2536046/extract-directory-path-and-filename
answered Mar 29 '10 at 6:30