From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Friedrich Dominicus Newsgroups: gmane.emacs.help Subject: Re: A very simple question on SED or AWK for a GURU, possibly a lisp script or emacs batch processing of many files Date: 14 Jan 2003 08:13:56 +0100 Organization: Q Software Solutions GmbH Sender: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <874r8ckxu3.fsf@fbigm.here> References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1042528391 26479 80.91.224.249 (14 Jan 2003 07:13:11 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Tue, 14 Jan 2003 07:13:11 +0000 (UTC) Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18YLG1-0006sk-00 for ; Tue, 14 Jan 2003 08:13:09 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18YLEM-0006Kh-04 for gnu-help-gnu-emacs@m.gmane.org; Tue, 14 Jan 2003 02:11:26 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!logbridge.uoregon.edu!newsfeed.vmunix.org!newsfeed.stueberl.de!newsfeed01.sul.t-online.de!newsmm00.sul.t-online.com!t-online.de!news.t-online.com!not-for-mail Original-Newsgroups: gnu.misc.discuss,comp.lang.lisp,gnu.emacs.help Original-Followup-To: comp.lang.lisp Original-Lines: 64 Original-X-Trace: news.t-online.com 1042528200 04 3404 4ym-E6NSiYFuk 030114 07:10:00 Original-X-Complaints-To: abuse@t-online.com X-Sender: 320004655587-0001@t-dialin.net User-Agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Military Intelligence) Original-Xref: shelby.stanford.edu gnu.misc.discuss:79553 comp.lang.lisp:102956 gnu.emacs.help:108932 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:5460 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:5460 gnuist006@hotmail.com (gnuist006) writes: > Here is the type of lines I have in a file: > > junk label="junk1/junk2/junk3/.../junkn/" more junk > > I want to find every line that has > > label="..." > > pattern > > and then I want to replace every / by _ inside the > quotes. > > For the purposes of continuity, I want the script to look like this: > > cat file | > sed commands | > awk commands | you do not nead cat for just one file. > > etc. > > I do not care if it all sed or awk or in what order. Well you posted to c.l.lisp here's a Lisp solutoin for one file. It is left to you to expand to more files (which is not too difficult) (defun q-2003-01-14 (in-file) (let ((out-file (concatenate 'string (subseq in-file 0 (position #\. in-file :from-end t)) ".out"))) (with-open-file (out out-file :direction :output :if-does-not-exist :create :if-exists :supersede) (clawk:for-file-lines (in-file) (when (clawk:match clawk:$0 "label=\"\(.*)\"") (let* ((submatch (aref clawk:*regs* 1)) (substr (subseq clawk:$0 (car submatch) (cdr submatch)))) (replace clawk:$0 (pregexp-replace* "/" substr "_") :start1 (car submatch) :end1 (cdr submatch)))) (princ clawk:$0 out) (terpri out) (values))))) With this file junk label="junk1/junk2/junk3/junk4" other stuff other junk label="j1/j2/j3" other stuff and much more nothing label="/t1/t2/t3" I got this result junk label="junk1_junk2_junk3_junk4" other stuff other junk label="j1_j2_j3" other stuff and much more nothing label="_t1_t2_t3" Quite nice scripting with Common Lisp IMHO :) Regards Friedrich