Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 17 Sep 2005 19:40:58 -0400
From:      Aaron Peterson <dopplecoder@gmail.com>
To:        Gary Kline <kline@tao.thought.org>
Cc:        FreeBSD Mailing List <freebsd-questions@freebsd.org>
Subject:   Re: how to rename a file with "!", "?", and other strange chars?
Message-ID:  <45d750d205091716402ca5e241@mail.gmail.com>
In-Reply-To: <20050917232747.GA76966@thought.org>
References:  <20050917232747.GA76966@thought.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On 9/17/05, Gary Kline <kline@tao.thought.org> wrote:
>=20
>         I scarfed up a slew of php files that are around 100 bytes
>         in strlen and with "\ " and other non-shell-friendly bytes.
>         Is there a way to use perl to chop off the first N bytes?
>=20
>         For example, a file many be named 00001\
>         00002xyz\?00003=3DTest.php.  What's the most logical way to
>         perl this file to "Test.php?

a script you run as:

% script.pl *

from the directory these files are in might look like:

foreach $old (@ARGV) {
  $new =3D $old;
  $new =3D~ s/\W//g;
  rename $old, $new;
}

That would remove all non "word" characters in the filename.  Perl
defines word characters as A-Z 0-9 and underscores.

or you could do something like this:

foreach $old (@ARGV) {
  $old =3D~ /(\w+\.php)/;
  rename $old, $1;
}

which catches any series of one or more word characters, a period, and
"php" in the variable $1.

There are lots of options, sounds like  you need a book on perl
maybe...  There is good online documentation here:

http://perldoc.perl.org/perl.html

Aaron



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?45d750d205091716402ca5e241>