ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
OK. The 0 after % pads with zeroes. d is the decimal radix spec. Now
$ printf "%02d\n" 012
10
$
012, because of the leading zero, is interpreted in octal! How is this?
@Tinkster: I think I'd give the whole script:
Code:
#!/bin/bash
#
#
# This script takes a .cue file as input and the corresponding .flac,
# producing a set of .wav files. I suggest to keep the .cue and this
# file in the same dir. The .cue file is CD5\ Nos.17\,18\,19\,20\,21.cue.
# The .flac is CD5 Nos.17,18,19,20,21.flac.
# WARNING: erase all .wav previously written by this script before running.
# flac writes the .wav as read only. It it finds a .wav file of
# the same name from a previous run, it will try to overwrite it.
# But the file will be read only.
file=$1
infile=$1".cue"
FLACFILE=$1".flac"
FIRST=1
CONT=01
while read A1 A2 A3 # TRACK 08 AUDIO
do
if [ "$A1" == "TRACK" ]
then
read A1 A2 # TITLE "Piano ..........."
read A1 A2 A3 # INDEX 00 40:18:43 (mm:ss:ff)
# We must transform mm:ss:ff into mm:ss.ss
# where ss.ss is secons and decimal fraction
old="$new"
new="$A3" # 40:18:43
if [ $FIRST == 1 ]
then
FIRST=0
else
old1="${old%:*}" #strips off everything from the final ":" to the end.
new1="${new%:*}"
old2="${old##*:}" #strips off everything from the beginning to the final ":".
new2="${new##*:}"
(("old2 = 10#$old2 * 100 / 75")) # ff -> ss/75
(("new2 = 10#$new2 * 100 / 75"))
old1=$old1"."$old2 # old1= mm:ss.ss
new1=$new1"."$new2
WAVFILE="$file"$CONT".wav"
echo "$old1 $new1 $WAVFILE"
# flac -f --decode --skip=$old1 --until=$new1 -o "$WAVFILE" "$FLACFILE"
((CONT = CONT + 1))
fi
fi
done < "$infile"
WAVFILE="$file"$CONT".wav"
echo "$new1 $WAVFILE"
#flac -f --decode --skip=$new1 -o "$WAVFILE" "$FLACFILE"
exit
I know I will find here what I need. The info and man pages for printf merely say it is similar to the C printf function, point out the differences.
EDIT: Here is the full code with due modifications plus its output:
Code:
semoi@darkstar:~/BEETHOVEN/Wilhelm Backhaus - The 32 Beethoven Piano Sonatas/CD5/CD5_done$ cat t18.sh
#!/bin/bash
#
#
# This script takes a .cue file as input and the corresponding .flac,
# producing a set of .wav files. I suggest to keep the .cue and this
# file in the same dir. The .cue file is CD5\ Nos.17\,18\,19\,20\,21.cue.
# The .flac is CD5 Nos.17,18,19,20,21.flac.
# WARNING: erase all .wav previously written by this script before running.
# flac writes the .wav as read only. It it finds a .wav file of
# the same name from a previous run, it will try to overwrite it.
# But the file will be read only.
file=$1
infile=$1".cue"
FLACFILE=$1".flac"
FIRST=1
CONT=01
while read A1 A2 A3 # TRACK 08 AUDIO
do
if [ "$A1" == "TRACK" ]
then
read A1 A2 # TITLE "Piano ..........."
read A1 A2 A3 # INDEX 00 40:18:43 (mm:ss:ff)
# We must transform mm:ss:ff into mm:ss.ss
# where ss.ss is secons and decimal fraction
old="$new"
new="$A3" # 40:18:43
if [ $FIRST == 1 ]
then
FIRST=0
else
old1="${old%:*}" #strips off everything from the final ":" to the end.
new1="${new%:*}"
old2="${old##*:}" #strips off everything from the beginning to the final ":".
new2="${new##*:}"
(("old2 = 10#$old2 * 100 / 75")) # ff -> ss/75
(("new2 = 10#$new2 * 100 / 75"))
old1=$old1"."$old2 # old1= mm:ss.ss
new1=$new1"."$new2
printf -v CONT2 "%002d" $CONT
WAVFILE="$file"$CONT2".wav"
echo "$old1 $new1 $WAVFILE"
# flac -f --decode --skip=$old1 --until=$new1 -o "$WAVFILE" "$FLACFILE"
((CONT = CONT + 1))
fi
fi
done < "$infile"
printf -v CONT2 "%002d" $CONT
WAVFILE="$file"$CONT2".wav"
echo "$new1 $WAVFILE"
#flac -f --decode --skip=$new1 -o "$WAVFILE" "$FLACFILE"
exit
semoi@darkstar:~/BEETHOVEN/Wilhelm Backhaus - The 32 Beethoven Piano Sonatas/CD5/CD5_done$ ./t18.sh CD5\ Nos.17\,18\,19\,20\,21
00:00.0 08:28.13 CD5 Nos.17,18,19,20,2101.wav
08:28.13 14:45.26 CD5 Nos.17,18,19,20,2102.wav
14:45.26 21:13.97 CD5 Nos.17,18,19,20,2103.wav
21:13.97 27:35.57 CD5 Nos.17,18,19,20,2104.wav
27:35.57 31:21.33 CD5 Nos.17,18,19,20,2105.wav
31:21.33 35:28.26 CD5 Nos.17,18,19,20,2106.wav
35:28.26 40:18.0 CD5 Nos.17,18,19,20,2107.wav
40:18.0 43:53.40 CD5 Nos.17,18,19,20,2108.wav
43:53.40 47:21.77 CD5 Nos.17,18,19,20,2109.wav
47:21.77 50:27.84 CD5 Nos.17,18,19,20,2110.wav
50:27.84 53:40.97 CD5 Nos.17,18,19,20,2111.wav
53:40.97 62:36.89 CD5 Nos.17,18,19,20,2112.wav
62:36.89 65:53.17 CD5 Nos.17,18,19,20,2113.wav
65:53.17 CD5 Nos.17,18,19,20,2114.wav
semoi@darkstar:~/BEETHOVEN/Wilhelm Backhaus - The 32 Beethoven Piano Sonatas/CD5/CD5_done
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.