[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: OT: scripting question



Thus spake Michael D. Schleif:
> 
> Stephen Gran wrote:
> > 
> > Hello all,
> > What I'd like to end up with is a short script that will scan my music
> > directories and output to a file.  I'd like this to strip off the full
> > path and any ending extension, and ideally leave a blany\k line in
> > between directories.  The best I can do so far is :
> > ls -R /home/mp3 | (read filename; while [ ! -z "$filename" ]; do echo "${filename//mp3/ }" >> mp3.list; read filename; done)
> > This strips the extensions (almost all mp3's - built up from before I
> > found out about Ogg Vorbis), but I'm left with the full path and no
> > blank line between directories.  I seem to think the blank line could be
> > inserted by a "if filename is a directory, then echo "$filename" >>
> > mp3.list followed by \n", but I can't quite work out how to do it.  man
> > bash is giving me a headache, and I thought I'd turn to you guys and
> > gals.
> > Any thoughts?
> 
> How about this?
> 
> 
> #!/bin/sh
> DIR=/home/mds
> for dir in `find $DIR -type d | sort`
> do
>         echo $dir
>         echo
>         for file in `find $dir -maxdepth 1 -type f | sort`
>         do
>                 printf "\t"
>                 echo $file | sed 's!^.*/!!' | sed 's!\..*$!!'
>         done
>         echo;echo
> done
> exit 0
> 
> 
> What do you think?
> 
> -- 
> 
> Best Regards,
I think that you, kind sir, are the man.  I thought perhaps sed was my
friend in this case, but I don't know it that well yet.  Ah well, man
sed it is.  Thanks again.
Steve

-- 
"Today, of course, it is considered very poor taste to use the F-word
except in major motion pictures."
		-- Dave Barry, "$#$%#^%!^%&@%@!"

Attachment: pgp9jnpH4IyVN.pgp
Description: PGP signature


Reply to: