From owner-freebsd-questions@FreeBSD.ORG Sat Sep 17 23:41:00 2005 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 12E4816A41F for ; Sat, 17 Sep 2005 23:41:00 +0000 (GMT) (envelope-from dopplecoder@gmail.com) Received: from zproxy.gmail.com (zproxy.gmail.com [64.233.162.201]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9E1DE43D45 for ; Sat, 17 Sep 2005 23:40:59 +0000 (GMT) (envelope-from dopplecoder@gmail.com) Received: by zproxy.gmail.com with SMTP id 40so301749nzk for ; Sat, 17 Sep 2005 16:40:59 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=QE4kAn1coln6RnlT/mUVG6vww2U5tJdi79mFtmOB0hXE8rpNgVccMbBiItDtUF9DQAhT8mfT4F8FlATph4Dqas03y1bo60C8rjo4uherYKUjp86NE3EjUDfcsBlcuJrEk2A0+q3y5aaduIoFGxT5URSFMoUp3bOpGMg5s1Nj89w= Received: by 10.37.14.80 with SMTP id r80mr1662539nzi; Sat, 17 Sep 2005 16:40:58 -0700 (PDT) Received: by 10.36.128.17 with HTTP; Sat, 17 Sep 2005 16:40:58 -0700 (PDT) Message-ID: <45d750d205091716402ca5e241@mail.gmail.com> Date: Sat, 17 Sep 2005 19:40:58 -0400 From: Aaron Peterson To: Gary Kline In-Reply-To: <20050917232747.GA76966@thought.org> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <20050917232747.GA76966@thought.org> Cc: FreeBSD Mailing List Subject: Re: how to rename a file with "!", "?", and other strange chars? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: dopplecoder@gmail.com List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 17 Sep 2005 23:41:00 -0000 On 9/17/05, Gary Kline 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