From owner-freebsd-questions Mon Nov 26 6:44: 2 2001 Delivered-To: freebsd-questions@freebsd.org Received: from guru.mired.org (okc-65-31-203-60.mmcable.com [65.31.203.60]) by hub.freebsd.org (Postfix) with SMTP id DC11137B416 for ; Mon, 26 Nov 2001 06:43:57 -0800 (PST) Received: (qmail 61413 invoked by uid 100); 26 Nov 2001 14:43:56 -0000 From: Mike Meyer MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <15362.21804.774942.105080@guru.mired.org> Date: Mon, 26 Nov 2001 08:43:56 -0600 To: Devin Smith Cc: questions@freebsd.org Subject: Re: Scripting Problems please help In-Reply-To: <99357027@toto.iv> X-Mailer: VM 6.90 under 21.1 (patch 14) "Cuyahoga Valley" XEmacs Lucid X-face: "5Mnwy%?j>IIV\)A=):rjWL~NB2aH[}Yq8Z=u~vJ`"(,&SiLvbbz2W`;h9L,Yg`+vb1>RG% *h+%X^n0EZd>TM8_IB;a8F?(Fb"lw'IgCoyM.[Lg#r\ 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 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. 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