Help w Script to Rename Files Please. 
Author Message
 Help w Script to Rename Files Please.

I would like to rename all files starting with 'sys' in a directory to 'osys'.

I tried using the following script from the comp.unix.questions faq:

#!/usr/bin/perl -d
#
# rename script examples from lwall:
#       rename 's/\.orig$//' *.orig
#       rename 'y/A-Z/a-z/ unless /^Make/' *
#       rename '$_ .= ".bad"' *.f
#       rename 'print "$_: "; s/foo/bar/ if <stdin> =~ /^y/i' *

        $op = shift;

            $was = $_;
            eval $op;

            rename($was,$_) unless $was eq $_;
                    }

From within the directory containing the files, I typed:
rename sys* osys*
I got the message:
rename: =: not found

Can anyone
1. tell me how to use this script to do my rename?
2. explain the curious error message?

 Thanks,
 Ed Bachmann



Tue, 20 May 1997 04:46:35 GMT  
 Help w Script to Rename Files Please.

Quote:

>I would like to rename all files starting with 'sys' in a directory to 'osys'.

>I tried using the following script from the comp.unix.questions faq:

>#!/usr/bin/perl -d
>#
># rename script examples from lwall:
>#       rename 's/\.orig$//' *.orig
>#       rename 'y/A-Z/a-z/ unless /^Make/' *
>#       rename '$_ .= ".bad"' *.f
>#       rename 'print "$_: "; s/foo/bar/ if <stdin> =~ /^y/i' *

>        $op = shift;

>            $was = $_;
>            eval $op;

>            rename($was,$_) unless $was eq $_;
>                    }

>From within the directory containing the files, I typed:
>rename sys* osys*
>I got the message:
>rename: =: not found

>Can anyone
>1. tell me how to use this script to do my rename?

The script wants a perl statement followed by a list of filenames.
The statement is evaluated with each of the filenames in the $_ Variable.
If the filename has changed, the file is renamed to the new name.

So the call sould have been for instance

  rename 's/^sys/osys/' sys*

Quote:
>2. explain the curious error message?

No.  That depends on the content of your directory.

Anno



Tue, 20 May 1997 21:30:19 GMT  
 Help w Script to Rename Files Please.

Quote:

>I would like to rename all files starting with 'sys' in a directory to 'osys'.

>I tried using the following script from the comp.unix.questions faq:
...
>#       rename 's/\.orig$//' *.orig
>#       rename 'y/A-Z/a-z/ unless /^Make/' *
...
>From within the directory containing the files, I typed:
>rename sys* osys*
>I got the message:
>rename: =: not found

>Can anyone
>1. tell me how to use this script to do my rename?
>2. explain the curious error message?

rename uses perl syntax not shell syntax.  It applies a perl
command to the filename.

In your case, you want:  

        rename 's/^sys/osys/' *

I'm not sure where you got the error message.  I think it comes
from interpreting the first of your filenames as a substitution
command.

-Dave



Tue, 20 May 1997 08:41:05 GMT  
 Help w Script to Rename Files Please.
: I would like to rename all files starting with 'sys' in a directory to 'osys'.
:
: I tried using the following script from the comp.unix.questions faq:
:
: #!/usr/bin/perl -d
: #
: # rename script examples from lwall:
: #       rename 's/\.orig$//' *.orig
: #       rename 'y/A-Z/a-z/ unless /^Make/' *
: #       rename '$_ .= ".bad"' *.f
: #       rename 'print "$_: "; s/foo/bar/ if <stdin> =~ /^y/i' *
:
:         $op = shift;

:             $was = $_;
:             eval $op;

:             rename($was,$_) unless $was eq $_;
:                     }
:
: From within the directory containing the files, I typed:
: rename sys* osys*
: I got the message:
: rename: =: not found
:
: Can anyone
: 1. tell me how to use this script to do my rename?
: 2. explain the curious error message?

It looks like your system isn't interpreting the #! line.  The error message
is a shell message, not a perl message.  You may have to use this trick:

#!/bin/sh -a                            # perl, really

"true" || eval 'exec /usr/bin/perl -S $0 $argv:q';

& eval 'exec /usr/bin/perl -S $0 $argv:q'
    if 0;

Larry



Tue, 27 May 1997 04:36:46 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. QuickReport 2 Professional full of bugs?

2. faqclpb.zip comp.lang.pascal.borland mini FAQ

3. "Rename-File-Names" Script Needed, Please

4. "Rename-File-Names" Script Needed, Please

5. "Rename-File-Names" Script Needed, Please

6. File Renaming Problem (Please Help...)

7. File Renaming Problem (Please Help...)

8. Ado urgent

9. TPW Owl and Postscript problems - Help!

10. renaming file problem (rename / mv)

11. Perl Script to Rename files for Mon

12. Using rename script to change multiple files

 

 
Powered by phpBB® Forum Software