LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   script for compiling a playlist (http://www.linuxquestions.org/questions/linux-server-73/script-for-compiling-a-playlist-647219/)

sthompson 06-05-2008 11:43 AM

script for compiling a playlist
 
ok i use liquidsoap to play a stream of music and i have created a script to make a playlist and i was woundering how to get the list to form in alphebetical order right now i have

find /icecast -name '*.mp3' > /test.txt

and that compiles a random list of the mp3's
what would i have to add for it to be alpebetical??

colucix 06-05-2008 11:54 AM

Pipe the output of find to sort
Code:

find /icecast -name "*.mp3" | sort > /test.txt

sthompson 06-05-2008 11:57 AM

thanks that was simple and quick thanks colucix

do you know if there was a way i could get a file to insert in to the play list in between each
ex:

1broadcast.mp3
annoucment.mp3
2broadcast.mp3

i ask this cause all my mp3's are dated and i would like to insert a annoucement between them

sarin 06-05-2008 01:31 PM

Save the below lines in a file (say song.sh)
After changing the permissions etc, do ./song.sh < test.txt

lines=`wc -l test.txt | cut -f 1 -d" "`
while [ $lines -gt 0 ]
do
read song
echo $song
echo /path/ann.mp3
lines=`expr $lines - 1 `
done


(Hmm... I think I feel really bored today :) )

colucix 06-05-2008 02:25 PM

Do you want to insert the same line "announcement.mp3" between each line? You can do in many ways using sed or awk one-liners, for example:
Code:

awk '{print; print "announcement.mp3"}' test.txt
with awk you have to redirect the output to a file and then substitute the original one. Instead, with the following sed command you can use the -i option to edit the file in place, substituting the end of line with a newline character followed by the string "announcement.mp3":
Code:

sed -i 's/$/\nannouncement.mp3/g' test.txt
I'm sure there are better and more elegant ways to do the same, anyway. Cheers! :)

sthompson 06-05-2008 02:42 PM

thanks guys i'll test them when i get a chance

sthompson 06-05-2008 03:49 PM

with the sed command what is the change to make it every 2 lines or more

colucix 06-05-2008 05:38 PM

Code:

sed -i '0~3{s/$/\nannouncement.mp3/}' test.txt
This executes the substitution every three lines starting from zero. The 0~3 part is the address in the form M~N, where M is the starting line and N the step. You can play with different values to see how it works, but you actually need to change the step only, to make it every 2 lines or more.

sthompson 06-05-2008 06:34 PM

thanks again colucix


All times are GMT -5. The time now is 03:43 PM.