I have a variable myVar
in bash containing a long string that looks like this:
-rw-rw-rw- root/root 16 2018-02-12 10:03 foo_tar/baz1234_
I want to delete everything in myVar
before the last slash (including the last slash), so that myVar
ends up storing only baz1234_
. How can I remove everything and store the result in a variable?
I have encountered solutions dealing with sed, but those tackle file handling, hence my question.
ls -l
. What is exactly your need? – dr_ Feb 12 '18 at 09:09tar
archives, each one of them containing multiple files. I loop through them as to get a specific file that starts withbaz
, is followed by some digits and finally with an underscore_
. Inside eachtar
archive there is one such file, for which I want to get the name and output it on a csv file. I get the aforementioned output using thetar
command, looking for that specific file, but get that long string, for which I only want the final part. I store that in a variable, and print it then, alongside other information, on a csv file. – jlnkls Feb 12 '18 at 10:09basename -- "$myVar"
– Sundeep Feb 12 '18 at 10:48