last occurrence of a char in string
Hello,
i have a couple of string paths like: /vmfs/volumes/002264987352/vsma/uma.vrz /vmfs/volumes/00226498882/tsda.trz .. i want to substitude the strigs from the last occurrence of / that i have only the filenames like uma.vrz and tsda.trz. How to do that any idea? Thanks |
Code:
echo '/vmfs/volumes/002264987352/vsma/uma.vrz' | awk -F"/" '{print $NF}' Code:
echo '/vmfs/volumes/002264987352/vsma/uma.vrz' | sed 's#.*/##g' |
Quote:
Thank you, it works perfect. |
You are Welcome. Please mark the thread as Solved!!
|
If using bash 4+ you can use this as well in a script:
Code:
a='/vmfs/volumes/002264987352/vsma/uma.vrz' |
Quote:
Code:
c@CW8:~$ bash --version |
for filenames, try basename and dirname
If the question is parsing filenames to get the path and/or file name, you might want to look into dirname and basename:
$ fullname="some/long/path/to/thisfile.txt" $ dirname $fullname some/long/path/to $ pathname $fullname thisfile.txt |
All times are GMT -5. The time now is 09:08 PM. |