From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Rusi Newsgroups: gmane.emacs.help Subject: Re: Search and replace for a single file using a pattern file Date: Thu, 4 Jan 2018 08:54:29 -0800 (PST) Message-ID: <86e91daa-2540-4683-8828-e4a0a91563a6@googlegroups.com> References: <240d8da5-5078-4ecc-a285-0719841d124a@googlegroups.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1515084852 12646 195.159.176.226 (4 Jan 2018 16:54:12 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 4 Jan 2018 16:54:12 +0000 (UTC) Injection-Date: Thu, 04 Jan 2018 16:54:30 +0000 User-Agent: G2/1.0 To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jan 04 17:54:08 2018 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eX8mL-0002lX-Lc for geh-help-gnu-emacs@m.gmane.org; Thu, 04 Jan 2018 17:54:05 +0100 Original-Received: from localhost ([::1]:50290 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX8oK-0003si-KU for geh-help-gnu-emacs@m.gmane.org; Thu, 04 Jan 2018 11:56:08 -0500 X-Received: by 10.200.33.202 with SMTP id 10mr132390qtz.29.1515084870193; Thu, 04 Jan 2018 08:54:30 -0800 (PST) X-Received: by 10.31.50.193 with SMTP id y184mr16870vky.5.1515084869877; Thu, 04 Jan 2018 08:54:29 -0800 (PST) Original-Path: usenet.stanford.edu!g35no343807qtk.1!news-out.google.com!t48ni201qtc.1!nntp.google.com!g35no343798qtk.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help In-Reply-To: Complaints-To: groups-abuse@google.com Original-Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=117.195.51.162; posting-account=mBpa7woAAAAGLEWUUKpmbxm-Quu5D8ui Original-NNTP-Posting-Host: 117.195.51.162 Original-Xref: usenet.stanford.edu gnu.emacs.help:221454 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:115571 Archived-At: On Thursday, January 4, 2018 at 8:36:01 PM UTC+5:30, Rusi wrote: > On Thursday, January 4, 2018 at 3:32:32 PM UTC+5:30, Angus Comber wrote: > > I have some horrible logs where integers are printed for states and I w= ant to do a global search and replace on the file to eg replace integer x w= ith a string. > >=20 > > I can obviously do individually using c-m-% but that is fairly laboriou= s. So use of a search and replace mapping in a text file would be really c= onvenient. > >=20 > > Is this possible? any suggestions? >=20 > I'd combine Tom=C3=A1s Robert's solutions: >=20 > (defvar my-codes > '((1 . bread) > (2 . cheese) > (3 . wine)))=20 >=20 > (defun replace-all () > (interactive) > (dolist (x my-codes) > (replace-string (number-to-string (car x)) > (symbol-name (cdr x))))) >=20 > After which M-x replace-all > should do it Probably I should say that sed is the way to do this more than emacs/elisp $ cat sedsc s/1/bread/ s/2/cheese/ s/3/wine/ $ cat txt.txt 1 was my first meal 2 came after that and 3 to rinse it all=20 $ sed -f sedsc txt.txt bread was my first meal cheese came after that and wine to rinse it all=20