Hi,
I have a bash script that reads a file and stores it on an array.
The file is text, but msdos formated text: it is actually a a list of
mp3 files in .m3u format. It goes like this:
> #EXTM3U
> #EXTINF:54,01/ - Pietro Locatelli - SkyFM: Mostly Classical - Concerto Grosso in D Major, Op. 1, No. 9 , mvmt. II. Largo (Capella Istropolitana, Jaroslav Krecek)
> Classical\0000 -- Pietro Locatelli - Concerto Grosso in D Major, Op. 1, No. 9 , mvmt. II. Largo (Capella Istropolitana, Jaroslav Krecek).mp3
> #EXTINF:486,02/ - Mauro Giuliani - SkyFM: Mostly Classical - 12 Landler for Flute and Guitar (Mikail Helasvuo, Jukka Savijoki)
> Classical\0001 -- Mauro Giuliani - 12 Landler for Flute and Guitar (Mikail Helasvuo, Jukka Savijoki).mp3
> ...
The problem is that the script “removes” the backslash on the odds line
(excluding the first or header), which is not an escape, it is a DOS
path separator character (Classical\0000). I do not want that,
obviously: it breaks the workings of the file.
The problem happens here:
declare -a EXTINF
declare -a FULLNAME
COUNTTOT=0
NUMEROLINEAS=0
COUNTTOT=0
while read LINEA ; do
if $NUMEROLINEAS -eq 0 ]; then
HEADER=$LINEA
NUMEROLINEAS=1
continue
fi
ODD=`expr $NUMEROLINEAS % 2`
if $ODD -eq 1 ]; then
echo "ODD $NUMEROLINEAS -- $LINEA"
EXTINF$COUNTTOT]="$LINEA"
else
echo "EVEN $NUMEROLINEAS -- $LINEA"
#echo
FULLNAME$COUNTTOT]="$LINEA"
COUNTTOT=`expr $COUNTTOT + 1`
fi
NUMEROLINEAS=`expr $NUMEROLINEAS + 1`
done < $FICHERO
Simplifying the code for clarity, we get to this minimal script:
#!/bin/bash
COUNT=0
while read LINEA ; do
echo $LINEA
COUNT=`expr $COUNT + 1`
if $COUNT -ge 5 ]; then
break
fi
done < Classical.m3u
That’s all that is needed to see it. The sample file produces this:
> cer@AmonLanc:~/streamtuner2/L2> ./testbad
> #EXTM3U
> #EXTINF:54,01/ - Pietro Locatelli - SkyFM: Mostly Classical - Concerto Grosso in D Major, Op. 1, No. 9 , mvmt. II. Largo (Capella Istropolitana, Jaroslav Krecek)
> Classical0000 -- Pietro Locatelli - Concerto Grosso in D Major, Op. 1, No. 9 , mvmt. II. Largo (Capella Istropolitana, Jaroslav Krecek).mp3
> #EXTINF:486,02/ - Mauro Giuliani - SkyFM: Mostly Classical - 12 Landler for Flute and Guitar (Mikail Helasvuo, Jukka Savijoki)
> Classical0001 -- Mauro Giuliani - 12 Landler for Flute and Guitar (Mikail Helasvuo, Jukka Savijoki).mp3
> cer@AmonLanc:~/streamtuner2/L2>
Compare with the first code section of the post.
It is interesting to notice that the script eats the “”, but not the
control-M chars at the end of each line.
How can I avoid this?
–
Cheers / Saludos,
Carlos E. R.
(from 12.3 x86_64 “Dartmouth” at Telcontar)