From owner-freebsd-questions Wed Nov 11 15:59:01 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id PAA21462 for freebsd-questions-outgoing; Wed, 11 Nov 1998 15:59:01 -0800 (PST) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from ccsales.com (ccsales.com [216.0.22.30]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id PAA21450 for ; Wed, 11 Nov 1998 15:58:56 -0800 (PST) (envelope-from randyk@ccsales.com) Received: from ntrkcasa (b226.ecom.net [207.13.225.226]) by ccsales.com (8.9.1/8.9.0) with SMTP id PAA04031; Wed, 11 Nov 1998 15:57:17 -0800 (PST) Message-Id: <3.0.5.32.19981111155810.037f54a0@ccsales.com> X-Sender: randyk@ccsales.com X-Mailer: QUALCOMM Windows Eudora Pro Version 3.0.5 (32) Date: Wed, 11 Nov 1998 15:58:10 -0800 To: chuck@ucsd.edu, Zdenko Tomasic From: "Randy A. Katz" Subject: Re: find and replace within files. Cc: fabry@panam.edu, freebsd-questions@FreeBSD.ORG Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Hi again, Didn't read your thing and you said directory tree, you could get a list of the files first: Hello, in PERL: #!/usr/bin/perl chdir "/directorytostartwith"; @files = system("find . -print"); foreach $file (@files) { if (-f "$file") { ### If file is a text file open(FILE1,"$file"); open(FILE2,">$file.tmp"); while () { s/My Little Text/Replaced With/g; print FILE2; } close(FILE1); close(FILE2); system("mv $file.tmp $file"); } This will replace all instances of My Little Text with Replaced With and write it all out to FILE2 (mynewfile.txt). You can use regular expressions also in the s///; structure... At 02:57 PM 11/11/98 -0800, Chuck Rouillard wrote: >On Wed, 11 Nov 1998, Zdenko Tomasic wrote: > >> Take a look at perl. It is probably the most convenient tool for that. >> (I think it could be done as a 1-liner). >> >> ZT >> >> To Unsubscribe: send mail to majordomo@FreeBSD.org >> with "unsubscribe freebsd-questions" in the body of the message > >Perl or AWK. Perl especially. > > > >To Unsubscribe: send mail to majordomo@FreeBSD.org >with "unsubscribe freebsd-questions" in the body of the message > > To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message