From owner-freebsd-questions Mon Nov 26 8:24: 8 2001 Delivered-To: freebsd-questions@freebsd.org Received: from smtp6.mindspring.com (smtp6.mindspring.com [207.69.200.110]) by hub.freebsd.org (Postfix) with ESMTP id 7A17937B416 for ; Mon, 26 Nov 2001 08:24:00 -0800 (PST) Received: from user-38ldg1r.dialup.mindspring.com ([209.86.192.59] helo=Main) by smtp6.mindspring.com with smtp (Exim 3.33 #1) id 168OXt-0004dI-00; Mon, 26 Nov 2001 11:23:49 -0500 Message-ID: <002401c17696$972dd5e0$0300a8c0@jayyness.com> From: "Totally Jayyness" To: "Mike Meyer" , "Devin Smith" , Cc: References: <15362.21804.774942.105080@guru.mired.org> Subject: Re: Scripting Problems please help Date: Mon, 26 Nov 2001 09:22:48 -0700 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Thanks so much for the help guys. I will try that while/read combo. I currently have a script that will build a list of all the mp3 files and them parse them to a playlist. It is fairly simple but it gets that job done. # Parse mp3 files into m3u playlist find /mp3 -iname "*.mp3" > /mp3/allsongsbydir.txt sed -e 's;/mp3;http:12.159.64.5;' -e 's/ /%20/g' /mp3/allsongsbydir.txt > /mp3/allsongs.m3u So if I touched up that while/read, I should have something like this? #!/bin/sh find /usr/test -type d -print | while read songs do (cd "$songs"; find -iname "*.mp3" > "$songs.m3u") done ok, cool... I hope that is right. Can't wait to try it. Hmmm, ok, this looks like it will put just the songs in the output file, though, in order for the playlist to work, it needs the path to the file also... so I make this change... (find "$songs" -iname "*.mp3" > "$songs.m3u") And I think that puts me right back into the same problem as before, haven't real time tested it yet. Will do that as soon as I can and see what I get, in both formats. If worse comes to worse, I will build all the songs.m3u files in each directory... then figure out how to script adding the directory path in front of each song in the .m3u files. ----- Original Message ----- From: "Mike Meyer" To: "Devin Smith" Cc: Sent: Monday, November 26, 2001 7:43 AM Subject: Re: Scripting Problems please help > Devin Smith types: > > [snip] > > > > What I woudl like to do is have a script search each of the directories = > > > > for mp3 files and dump that output into a .m3u (playlist file) in it. = > > > > for example.. > > > > > > #!/bin/sh > > > find . -type d -print | > > > while read x > > > do > > > (cd "$x"; ls *.mp3 > "$x.m3u") > > > done > > > > Might I suggest the following small changes, assuming you want *all* the mp3 > > files listed in one playlist. > > > > #!/bin/sh > > find . -type d -print | > > while read x > > do > > (cd "$x"; ls | grep -i mp3 >> "~/playlist.m3u") > > done > > > > which also has the advantage of listing files which end in uppercase or mixed case, i.e. song.MP3 or song.Mp3. > > Ah - good point; the "grep -i" instead of ls'ing for just the thing > you want in one case. You could also use "ls *.[Mm][Pp]3". You do need > to change it to "grep -i 'mp3$' to avoid false positives, though. > > However, if you just want one big playlist, why fool with the read > loop at all: > > find . -name '*.[Mm][Pp]3' | sed 's;^.*/;;' > ~/playlist.m3u > or > find . -type f | sed -n -e 's;^.*/;;' -e '/[Mm][Pp]3$/p' > ~/playlist.m3u > or > find . -type f | grep -i 'mp3$' | sed 's;^.*/;;' > ~/playlist.m3u > or > ... > > Oh yeah, while I'm here - it's best to capture the output of a while > loop directly, not by appending to a file in the middle of the > loop. That keeps you from getting fouled up if you try and run it a > second time: > > find . -type d | > while read x > do > (cd "$x"; ls) > done | grep -i 'mp3$' > ~/playlist.m3u > > I moved the grep outside the loop so you only run it once while I was > at it. > > -- > Mike Meyer http://www.mired.org/home/mwm/ > Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-questions" in the body of the message To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message