🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.misc.discuss
Article #2158

Re: A very simple question on SED or AWK for a GURU, possibly a lisp script or emacs batch processing of many files

#2158
From: Alan Mackenzie
Date: Tue, 14 Jan 2003 22:54
35 lines
2374 bytes
gnuist006 <gnuist006@hotmail.com> 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").
Technical Details
Message-ID: <re420b.v5.ln@acm.acm>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!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
References: <b00bb831.0301131603.34e9704c@posting.google.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f4fd2,1e8c4b23af1e4636
X-Google-Attributes: gidf4fd2,public
X-Google-Thread: 103b8b,1e8c4b23af1e4636
X-Google-Attributes: gid103b8b,public
X-Google-Thread: 1025b4,1e8c4b23af1e4636
X-Google-Attributes: gid1025b4,public
X-Google-ArrivalTime: 2003-01-14 15:00:52 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!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
From: Alan Mackenzie<none@example.invalid>
Newsgroups: gnu.misc.discuss,comp.lang.lisp,gnu.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
Lines: 36
Message-ID: <re420b.v5.ln@acm.acm>
References: <b00bb831.0301131603.34e9704c@posting.google.com>
NNTP-Posting-Host: acm.muc.de
X-Trace: marvin.muc.de 1042585012 9059 193.149.49.134 (14 Jan 2003 22:56:52 GMT)
X-Complaints-To: news-admin@muc.de
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))