I have a couple of folders that are audiobooks. The files are numbered and I want to convert them to one file. I used the following script to convert them:
#!/bin/bash
if [ ! -d mp3 ]; then
mkdir -p mp3;
fi;
for f in ./*.flac; do echo "file '$f'" >> mylist.txt; done
ffmpeg -f concat -safe 0 -i mylist.txt -b:a 320k mp3/title.mp3
[ -e mylist.txt ] && rm mylist.txt
My problem is that I have to rename the first ten files because they are not in the right order. The files are named 1 - Title, 2 - Title, 3 - Title and so on. To get the right order I have to rename them to 01 - Title, 02 - Title, ..., 09 - Title. How can I do that with a bash script ? Furthermore it would be nice, if the playlist.m3u file would be changed accordingly.
Thanks for your help.
@Cyrus posted the right Link to solve my problem. The solved script ist:
#!/bin/bash
if [ ! -d mp3 ]; then
mkdir -p mp3;
fi;
for f in ./*.flac; do echo "file '$f'" >> mylist2.txt; done
sort -V mylist2.txt >> mylist.txt
rm mylist2.txt
ffmpeg -f concat -safe 0 -i mylist.txt -b:a 320k mp3/title.mp3
[ -e mylist.txt ] && rm mylist.txt