I have files which all look like this: filename.bla_1
of cours I cannot know if the filename has "_" in it. could be file_name.bla_1. I want to write a function that take filename and delete the _# at the end. filename.bla_1 will be --> filename.bla
echo $filename | rev | cut -d "_" -f2 | rev
will do the trick if the file doesn't have "" in the name but I want to make sure this works also for filenames with ""
'
instead of"
for your delimeter string?echo $filename | rev | cut -d '_' -f2 | rev
seems to do the job for me, with filenames containing both"
and'
.