How to extract string from filename

Tony Baechler tony at
Thu Jul 30 08:52:13 UTC 2015

Thanks!  Yes, that worked.  I had to use rev twice as you suggested.  This 
single line script seems to do what I want:

for file in *.mp3; do basename $file _default.mp3 | rev | cut -d_ -f1 | rev; 

I can then design a further wrapper script to take the PID, download the web 
page and name it the same as the original filename with an html extension. 
This is perfect!  I hadn't heard of rev before.  I not only learned 
something new, but I now have a solution for the next time I run into a 
situation like this.

On 7/29/2015 4:58 AM, Willem van der Walt wrote:
> Hi,
> I usually use rev twice, e.g.
> echo blablabla_bla_p123_default.mp3|rev|cut -f2 -d'_'|rev
> HTH, Willem

More information about the Blinux-list mailing list