Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Bash script variable manipulation, how to remove characters?
I've wrote a script to convert a .mp3 into .spx, but the output of files are <filename>.mp3.spx, and I would prefer to get <filename>.spx, but I'm at a total loss of how to do it. (I'm aiming to convert around 2000 files)
I've looked a several bash scripting guides and can't figure out a way to do it. Here's the script
#!/bin/sh
for file in *.mp3
do madplay -q -m -R 16000 --output=raw:- $file | speexenc --16bit -w - ${file}.spx
done
Now I now I could run a separate command after to rename with regular expressions, but I was wondering if I could just change "${file}.spx" to something that would name the output how I wanted it, that would be great. If you tell me a little bit about how it works and why, that would be the greatest.
1 Answer
- nibblesthemouseLv 41 decade agoFavorite Answer
Change the last part to:
speexenc --16bit -w - ${file%.mp3}.spx
This will remove .mp3 from the end of $file, and then add .spx to the end of it.
Source(s): man bash