Lance Hoffmeyer <[EMAIL PROTECTED]> wrote:
>I have a number of subdirectories where I have files with - such as 
>name - title.txt and I wish to convert them to:
>name: title.txt
>
>In bash I tried:
>
>for i in *-*;do mv $i `echo $i | sed -e 's/ - /:/'`'done 
>
>but this gives me an error about moving multiple files and needing a directory

You need some additional quoting:

  for i in *-*; do mv "$i" "`echo $i | sed -e 's/ - /: '`"; done

... works for me.

>I also tried on e-line perl script
>
>perl -we '($new=$_) =~tr/\s-\s/:\s/ && rename _$,$new'
                                               ^^ Did you mean $_ here?
>but I get uninitialized value errors.

Yes, because Perl doesn't normally automatically iterate over its input;
you can do it manually, or various switches, like -n, cause it to do so.
tr/// is the wrong operator to use, too; see 'perldoc perlop'.

This works:

  ls -1 | perl -wne 'chomp; ($new=$_) =~ s/ - /: / and rename $_, $new'

You could also opendir() and readdir() yourself, though that's probably
too much effort for a one-liner. And, as somebody else has said, you
might as well just use the rename(1p) utility that comes with Perl.

>Also, how would I use these for multiple subdirectories at once?

Look for the recent discussion on this list on the use of find and
xargs.

-- 
Colin Watson                                     [EMAIL PROTECTED]

Reply via email to