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 07:05:58 -0800 (PST) Message-ID: 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 1515078561 32222 195.159.176.226 (4 Jan 2018 15:09:21 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 4 Jan 2018 15:09:21 +0000 (UTC) Injection-Date: Thu, 04 Jan 2018 15:05:59 +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 16:09:17 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 1eX78r-0007qX-45 for geh-help-gnu-emacs@m.gmane.org; Thu, 04 Jan 2018 16:09:13 +0100 Original-Received: from localhost ([::1]:41967 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eX7Aq-0005T1-3h for geh-help-gnu-emacs@m.gmane.org; Thu, 04 Jan 2018 10:11:16 -0500 X-Received: by 10.55.15.92 with SMTP id z89mr3422553qkg.24.1515078359384; Thu, 04 Jan 2018 07:05:59 -0800 (PST) X-Received: by 10.31.158.84 with SMTP id h81mr527096vke.6.1515078359113; Thu, 04 Jan 2018 07:05:59 -0800 (PST) Original-Path: usenet.stanford.edu!m31no289822qtf.0!news-out.google.com!t48ni175qtc.1!nntp.google.com!g35no286300qtk.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help In-Reply-To: <240d8da5-5078-4ecc-a285-0719841d124a@googlegroups.com> Complaints-To: groups-abuse@google.com Original-Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=117.223.154.245; posting-account=mBpa7woAAAAGLEWUUKpmbxm-Quu5D8ui Original-NNTP-Posting-Host: 117.223.154.245 Original-Xref: usenet.stanford.edu gnu.emacs.help:221453 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:115570 Archived-At: 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 wan= t to do a global search and replace on the file to eg replace integer x wit= h a string. >=20 > I can obviously do individually using c-m-% but that is fairly laborious.= So use of a search and replace mapping in a text file would be really con= venient. >=20 > Is this possible? any suggestions? I'd combine Tom=C3=A1s Robert's solutions: (defvar my-codes '((1 . bread) (2 . cheese) (3 . wine)))=20 (defun replace-all () (interactive) (dolist (x my-codes) (replace-string (number-to-string (car x)) (symbol-name (cdr x))))) After which M-x replace-all should do it