From owner-freebsd-questions Wed Jan 23 11:54:48 2002 Delivered-To: freebsd-questions@freebsd.org Received: from smtp.bcn.isoco.net (ldap.isoco.net [212.9.90.11]) by hub.freebsd.org (Postfix) with ESMTP id 5FD2137B400 for ; Wed, 23 Jan 2002 11:54:45 -0800 (PST) Received: from fxn.bcn.isoco.net (fxn.bcn.isoco.net [172.16.1.50]) by smtp.bcn.isoco.net (Postfix) with SMTP id AC3A2CD2B5 for ; Wed, 23 Jan 2002 20:54:43 +0100 (CET) Date: Wed, 23 Jan 2002 20:54:38 +0100 From: F.Xavier Noria To: freebsd-questions@freebsd.org Subject: Re: Text editiing.... possibility for perl? Message-Id: <20020123205438.23e003d3.fxn@isoco.com> In-Reply-To: References: X-Mailer: Sylpheed version 0.7.0 (GTK+ 1.2.10; i386--freebsd4.4) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Wed, 23 Jan 2002 13:34:27 -0600 Eric Six wrote: : I have a few questions.. I need to edit a few files with a bunch : text. I am creating forward and reverse zone file for a private : network and I want to automate this tedious process.. Here is what I : have. : : I create a basic template in excel, it is as follows; : : host15,1,in,a,10,50,15,1 : host15,2,in,a,10,50,15,2 : host15,3,in,a,10,50,15,3 : : : What I need done after this file is populated is make it look like : this; : host15-1 in a 10.50.15.1 : host15-2 in a 10.50.15.2 : host15-3 in a 10.50.15.3 : : So I need the first comma changed to a minus, the next two comma's a : tab, and the last three changed to periods. I can do some of this : with 'cut' but not everything I want to do... I figure I cannot be : the only one that has had to populate a massive amount of forward and : reverse files in bind.. I figure there might be a perl script for : this?? This one liner performs the transformation in place and leaves a backup of the original file called file.bak in the same directory: $ perl -pi.bak -e '$re="([^,]+)," x 7; s/$re/$1-$2\t$3\t$4\t$5.$6.$7./' file $ cat file host15-1 in a 10.50.15.1 host15-2 in a 10.50.15.2 host15-3 in a 10.50.15.3 -- fxn To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message