I am trying to get "abc.txt"
out of /this/is/could/be/any/path/abc.txt
using Unix command.
Note that /this/is/could/be/any/path
is dynamic.
Any idea?
Thanks in advance.
I am trying to get "abc.txt"
out of /this/is/could/be/any/path/abc.txt
using Unix command.
Note that /this/is/could/be/any/path
is dynamic.
Any idea?
Thanks in advance.
In
bash
:If your path has spaces in it, wrap it in
"
Then to extract the path, use the basename function
or
basename path
gives the file name at the end of pathEdit:
It is probably worth adding that a common pattern is to use back quotes around commands e.g. `basename ...`, so UNIX shells will execute the command and return its textual value.
So to assign the result of basename to a variable, use
and $x will be the file name.
You can use dirname command
You can use
basename /this/is/could/be/any/path/abc.txt