[LUNI] Scripting help

Carl Karsten carl at personnelware.com
Sat Nov 28 21:31:09 CST 2009


On Sat, Nov 28, 2009 at 9:12 PM, Timothy J. Wielgos <tim at wielgos.com> wrote:
> Hey all,
>
> I suck at scripting.
>
> There, I said it.
>
> I'm trying to write a script that will rename a bunch of mp3 files in my
> NAS.
>
> The files are named as such:
>
> [root at executor test]# ls
> 01. Jimmy Buffett - Cheeseburger in Paradise.flac
> 02. Jimmy Buffett - He Went to Paris.flac
> 03. Jimmy Buffett - Fins.flac
> ...
>
> I'm trying to name them as such:
>
> [root at executor test]# ls
> Jimmy Buffett - Cheeseburger in Paradise.flac
> Jimmy Buffett - He Went to Paris.flac
> Jimmy Buffett - Fins.flac
>
> The problem I'm having is that what I've written is capturing each word in
> the filename in the mfiles variable below, instead of capturing the entire
> line.  Here's what I've got:
>
> [root at executor ~]# cat changeit.sh
> #!/bin/bash
> n=1
> mfiles=`ls -1 $1`
> for file in $mfiles ; do
>   echo "mv $file $1/fixed/`cut -c 5- $file`"
> done
>
> where $1 is the directory name of the files to change.
>
> As I said, this is outputting something like this:
>
> [root at executor ~]# ./changeit.sh test
> cut: 01.: No such file or directory
> mv 01. test/fixed/
> cut: Jimmy: No such file or directory
> mv Jimmy test/fixed/
> cut: Buffett: No such file or directory
> mv Buffett test/fixed/
> ^C
> [root at executor ~]#
>
> Anyone have any tips on making this do what I want to do?
>
> Thanks,
> Tim
>
> --
> Linux Users Of Northern Illinois (Chicago) - Technical Discussion
> http://luni.org/mailman/listinfo/luni
>
>

If you are trying to do some programming, use Python.

If you just want to rename files, use rename:

$ man rename
       rename - renames multiple files

-- 
Carl K


More information about the LUNI mailing list