Given the scenario like this, if at all if have to use IFS on the below given example, how it should be used.
IFS=/
eg:
/xyz/123/348/file1
I want to use the last slash /file1 . So can anyone, suggest me how to pick the last "/" as a IFS.
Given the scenario like this, if at all if have to use IFS on the below given example, how it should be used.
IFS=/
eg:
/xyz/123/348/file1
I want to use the last slash /file1 . So can anyone, suggest me how to pick the last "/" as a IFS.
try this,
echo '/xyz/123/348/file1' | awk -F/ '{print FS$NF}'
echo '/xyz/123/348/file1' | sed 's;.*/;/;'
Hi, you do not need to use IFS for that, not an external program
$ file=/xyz/123/348/file1
$ echo ${file##*/}
file1
$ echo ${file%/*}
/xyz/123/348
How about basename - that is designed to return the file name from a path. It will optionally remove suffixes (like file extensions)
>f=path/to/mydirectory/file.c
>basename $f
file.c
>basename $f .c
file