From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: throopw@sheol.org (Wayne Throop) 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:10:59 GMT Organization: sheol Sender: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <1042582259@sheol.org> References: NNTP-Posting-Host: main.gmane.org X-Trace: main.gmane.org 1042584129 10785 80.91.224.249 (14 Jan 2003 22:42:09 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Tue, 14 Jan 2003 22:42:09 +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 18YZl1-0002nh-00 for ; Tue, 14 Jan 2003 23:42:07 +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 18YZk9-0007bH-04 for gnu-help-gnu-emacs@m.gmane.org; Tue, 14 Jan 2003 17:41:13 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!cyclone.bc.net!sjc70.webusenet.com!news.webusenet.com!gestalt.direcpc.com!telocity-west!DIRECTV!sn-xit-03!sn-xit-01!sn-post-02!sn-post-01!supernews.com!corp.supernews.com!not-for-mail Original-Newsgroups: gnu.misc.discuss,comp.lang.lisp,gnu.emacs.help,comp.unix.shell Original-Distribution: world Cache-Post-Path: sj-nntpcache-5!unknown@tent.cisco.com X-Cache: nntpcache 2.4.0b2 (see http://www.nntpcache.org/) Original-X-Complaints-To: abuse@supernews.com Original-Lines: 50 Original-Xref: shelby.stanford.edu gnu.misc.discuss:79560 comp.lang.lisp:103034 gnu.emacs.help:108960 comp.unix.shell:139636 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:5488 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:5488 : gnuist006@hotmail.com (gnuist006) : Even though the problem posed in this thread is still : : *** UNSOLVED *** : : let me extend my gratitude to Mr Christofer and Friedrich for their : kind attempts to answer this. I hope for some more help tonight. perl -pe 's-\b(label="[^"]*")- ((($x=$1) =~ s./._.g),$x) -ge' : I can write a bash wrapper loop but what I do not know here is how to : implement the core logic of replacing an indefinite number of : forward-slashes within a pattern of interest. s/\//_/g : I also want to use bash/sed/awk instead of perl. Why? Oh, well. You'd think this bit of awk-wardness would work by analogy with the perl above ` awk '{gsub("label=\"[^\"]*\"", gensub("\/","_","g","&"));print}' but it doesn't. Hrm. Maybe awk '{ s=$0; m=match(s,"label=\"[^\"]*\""); if(m){ pre =substr(s,1,RSTART-1); inf =substr(s,RSTART,RLENGTH); post=substr(s,RSTART+RLENGTH); gsub("/","_",inf); s= pre inf post; } print s; }' Yeah, that works, at least on the cases I tested. The perl is a tiny bit cleaner, though; the perl version handles multiple labels on a line, and the \b ensures the "label" isn't part of a larger word. Both of which are a bit tricky to do in awk. Doable, just not as easy. Plus which, the perl looks more like line noise, which is cool, and promotes job security. Wayne Throop throopw@sheol.org http://sheol.org/throopw