[PLUG] BASH string manipulation
Paul Lankow
paul at lankow.net
Mon Jun 16 10:12:02 UTC 2003
Thanks, Ali.
for F in *.[Mm][Pp]3 ; do # Find each .mp3 file
echo "Converting $F" # Show what we're working on
WF=`echo $F | tr a-z A-Z` # Convert to upper case
WF=${WF%\.*} # Strip extension
WF=${WF##*- } # Extract song title
WF="$WF".WAV # Complete the new filename
echo "Creating $WF" # Show resulting filename
mpg123 -w /storage/wav/"$WF" "$F" # Create a wav file from mp3
done
Works great. :-)
Regards,
Paul
> Well, I don't know how to fiddle with the case inside of bash,
> but I have done some stripping off of text.
>
>>text="The artist - Optional album title - Song title.mp3"
>>noext=${text%\.*}
>>echo $noext
> The artist - Optional album title - Song title
>>nopre=${noext##*- }
>>echo $nopre
> Song title
>>caps=`echo $nopre | tr a-z A-Z`
>>echo $caps
> SONG TITLE
____________________________
We can not direct the wind,
But we can adjust the sails.
-Bertha Calloway
More information about the PLUG
mailing list