From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: dkcombs@panix.com (David Combs) Newsgroups: gmane.emacs.help Subject: Re: How to apply a list of regex replaces to multiple files? Date: Fri, 1 Aug 2008 08:38:05 +0000 (UTC) Organization: Public Access Networks Corp. Message-ID: References: <091f39ab-89ac-438f-a878-464309c4a8f6@i18g2000prn.googlegroups.com> <6b08e826-8484-41ad-bf37-52845ec26a51@f24g2000prh.googlegroups.com> <8763ron1dr.fsf@lion.rapttech.com.au> NNTP-Posting-Host: lo.gmane.org X-Trace: ger.gmane.org 1217580180 20103 80.91.229.12 (1 Aug 2008 08:43:00 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 1 Aug 2008 08:43:00 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Aug 01 10:43:50 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KOqEh-0001lE-Vb for geh-help-gnu-emacs@m.gmane.org; Fri, 01 Aug 2008 10:43:44 +0200 Original-Received: from localhost ([127.0.0.1]:42648 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KOqDn-0007Ua-Ed for geh-help-gnu-emacs@m.gmane.org; Fri, 01 Aug 2008 04:42:47 -0400 Original-Path: news.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!news-out.readnews.com!transit3.readnews.com!panix!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 64 Original-NNTP-Posting-Host: panix1.panix.com Original-X-Trace: reader1.panix.com 1217579885 19370 166.84.1.1 (1 Aug 2008 08:38:05 GMT) Original-X-Complaints-To: abuse@panix.com Original-NNTP-Posting-Date: Fri, 1 Aug 2008 08:38:05 +0000 (UTC) X-Newsreader: trn 4.0-test76 (Apr 2, 2001) Original-Xref: news.stanford.edu gnu.emacs.help:160768 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:56117 Archived-At: In article <8763ron1dr.fsf@lion.rapttech.com.au>, Tim X wrote: >"michael.l" writes: > >> On Jul 1, 1:38 am, "Lennart Borgman (gmail)" >> wrote: >>> michael.l wrote: >>> > I've browsed the messages here and have googled but don't see a clear >>> > solution yet. I have about 900 documents to which I need to apply a >>> > list of maybe 40 separate regex search and replaces. I would like to >>> > feed a list of the regex expressions and replacements to emacs and >>> > have it applied to a directory of the files. Any solutions? Keyboard >>> > macros don't seem like the right solution.... >>> >>> Sounds like the best would be writing a small elisp function to do the job. >> >> I'll look into elisp...Struggled with perl to do this.... > >Well, not meaning to sound rude, but if you had trouble doing this with >perl, I suspect you will have even a harder time with elisp. I only say >this as, from your description, perl would be my first choice and it >should be pretty straight forward. I personally find perl regexp a lot >easier to work with and a lot more powerful than elisp's >implementation. After perl, my second choice would >likely be sed (actually, sed may be my first choice if you have quite a >number of regexp because you could put them all in a file and then just >run sed on the files - essentially, no programming. However, sed can be >a little tricky to wrap your head around as it has a hell of a lot of >power. > > >Tim > >-- >tcross (at) rapttech dot com dot au What I used to do is use "ex" (part of vi) or maybe it was "ed". Anyway, it had a "source" stmt, ie "source myRegexAndSubstituteCmds.ex", plus a sh-script ex foo.bar source ex foo2.bar source etc something like that. Anyway, it worked, for changing variable-names in about 100 program files, totally hands-off. Back then perl likely didn't even exist. David