From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Alan Mackenzie 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: Tue, 14 Jan 2003 22:54:19 +0000 Organization: muc.de e.V. -- private internet access Sender: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: References: NNTP-Posting-Host: main.gmane.org X-Trace: main.gmane.org 1042585613 17289 80.91.224.249 (14 Jan 2003 23:06:53 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Tue, 14 Jan 2003 23:06:53 +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 18Ya8x-0004UZ-00 for ; Wed, 15 Jan 2003 00:06:51 +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 18Ya7Q-0005ho-07 for gnu-help-gnu-emacs@m.gmane.org; Tue, 14 Jan 2003 18:05:16 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!news-fra1.dfn.de!news-nue1.dfn.de!uni-erlangen.de!lmu.de!news.muc.de!not-for-mail Original-Newsgroups: gnu.misc.discuss,comp.lang.lisp,gnu.emacs.help Original-Lines: 36 Original-NNTP-Posting-Host: acm.muc.de Original-X-Trace: marvin.muc.de 1042585012 9059 193.149.49.134 (14 Jan 2003 22:56:52 GMT) Original-X-Complaints-To: news-admin@muc.de Original-NNTP-Posting-Date: 14 Jan 2003 22:56:52 GMT User-Agent: tin/1.4.5-20010409 ("One More Nightmare") (UNIX) (Linux/2.0.35 (i686)) Original-Xref: shelby.stanford.edu gnu.misc.discuss:79561 comp.lang.lisp:103036 gnu.emacs.help:108961 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:5489 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:5489 gnuist006 wrote on 13 Jan 2003 16:03:15 -0800: > 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. Sounds like awk could be your tool of choice. Using gawk: cat file | gawk 'BEGIN {FS = "\""; OFS = "\""}; /[a-zA-Z_0-9]+=/ {gsub("/", "_", $2)}; {print}' (or something very like it) will do the job. Note: I haven't tested this. The solution assumes that the "junk" at the beginning of each line doesn't contain any "s. I would guess that alternative solutions, whether in Emacs lisp or perl or whatever would be much longer than this one-liner. The newsgroup comp.lang.awk might be a better place to ask such questions. Alternatively, email me if the above gawk program doesn't "quite" work, or you want me to explain it. > gnuist. -- Alan Mackenzie (Munich, Germany) Email: aacm@muuc.dee; to decode, wherever there is a repeated letter (like "aa"), remove half of them (leaving, say, "a").