ciwei wrote:
# ls -l
-rw-r--r-- 1 root other 0 Mar 19 16:24 this is the first file
-rw-r--r-- 1 root other 0 Mar 19 16:24 this is the second file
-rw-r--r-- 1 root other 0 Mar 19 16:24 this is the third file
I want to rename the files, to say, first, second, etc
# ls -1 | perl -ne 'print $1,"\n" if /(\w+)\s+file$/'
first
second
third
now try use rename
# ls -1 | perl -ne 'rename $_ , $1 if /(\w+)\s+file$/'
won't work, like nothing happed? why?
Because $_ contains a newline at the end.
Try this instead:
perl -le'/(\w+)\s+file$/ and rename $_, $1 or warn $! for <*file>'
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/