how to cut all string after the last delimiter?

hi all,

suppose a string:

abc/def/ghi/jkl/mn.txt

and i want to get the file name without the path.

however, different files have different paths, therefore the number of delimiter is uncertain.

thanks so much!

$ echo "abc/def/gh/joe.txt" | awk -F"/" '{print $NF}'
joe.txt
2 Likes

Try using basename <full_path_to_file>

$ basename /sndc002/app/appsndc/sndcappl/admin/sndc01.txt
sndc01.txt

1 Like

If you are doing this within a loop, you may want to consider using the built-in feature of bash/ksh parameter expansion. This will save you 1 exec for every loop

v="abc/def/ghi/jkl/mn.txt"
echo ${v##*/}
1 Like