Date: Mon, 26 Nov 2001 08:43:56 -0600 From: Mike Meyer <mwm@mired.org> To: Devin Smith <devin-freebsdquestions@rintrah.org> Cc: questions@freebsd.org Subject: Re: Scripting Problems please help Message-ID: <15362.21804.774942.105080@guru.mired.org> In-Reply-To: <99357027@toto.iv>
next in thread | previous in thread | raw e-mail | index | archive | help
Devin Smith <devin-freebsdquestions@rintrah.org> 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
--
Mike Meyer <mwm@mired.org> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?15362.21804.774942.105080>
