Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion sed multiple -e pattern match problem

Received: by 10.181.11.234 with SMTP id el10mr441403wid.2.1348233620173;
        Fri, 21 Sep 2012 06:20:20 -0700 (PDT)
Path: ed8ni9094913wib.0!nntp.google.com!feeder2.cambriumusenet.nl!feeder1.cambriumusenet.nl!feeder3.cambriumusenet.nl!feed.tweaknews.nl!94.232.116.13.MISMATCH!feed.xsnews.nl!border-3.ams.xsnews.nl!border4.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!border2.nntp.dca.giganews.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed.news.ucla.edu!usenet.stanford.edu!news.glorb.com!news-out.readnews.com!news-xxxfer.readnews.com!webuse.net!not-for-mail
From: "Ed Morton" <mortons...@gmail.com>
Newsgroups: comp.unix.shell
Subject: =?UTF-8?B?UmU6IHNlZCBtdWx0aXBsZSAtZSBwYXR0ZXJuIG1hdGNoIHByb2JsZW0=?=
Message-ID: <201209141758432493@webuse.net>
References: <529d3b82-b4eb-4af5-9288-a53437537218@n9g2000yqn.googlegroups.com> <201209141712262493@webuse.net> <50536bcf$0$1587$5fc30a8@news.tiscali.it>
Date: Fri, 14 Sep 2012 17:58:43 GMT
X-Newsreader: www.webuse.net
X-Complaints-To: abuse@webuse.net
NNTP-Posting-Host: 135.245.10.3
MIME-Version: 1.0
Bytes: 2232
Lines: 47
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Lem Novantotto <Le...@Hotmail.com> wrote:

> Ed Morton ha scritto:
> 
> > For anything else, use awk:
> 
> So "when the going gets awk, the awk's (awk, nawk, gawk) get going" eh? ;)
> 
> Yep, I know I should learn it some day. :-p

Yeah, it took me some convincing as I'd seen some horrible messes written in
old, broken awk (/usr/bin/awk on Solaris) and could never get the darn thing
to just BEHAVE in any sensible way but once I discovered the newer awks
(nawk, gawk, /usr/xpg4/bin/awk, etc.) the clouds parted and harps started
playing....

I've been using sed for 30 years and still use it fairly frequently, but I
think the only commands I use in it are "s" and "g". Once you start using
any other sed commands, awk's just simpler to write and more robust and even
for the simple stuff it's often more robust, e.g.:

$ echo "abc-def" | sed 's/-/\n/'
abcndef

$ echo "abc-def" | awk 'sub(/-/,"\n")'
abc
def

$ x="foo
> bar"

$ echo "abc-def" | sed "s/-/$x/"    
sed: -e expression #1, char 7: Unterminated `s' command
$ echo "abc-def" | sed 's/-/'"$x"'/'  
sed: -e expression #1, char 7: Unterminated `s' command

$ echo "abc-def" | awk -v x="$x" 'sub(/-/,x)'   
abcfoo
bardef

I think there's some combination of quotes that'll let sed understand the
embedded newline but it's just not worth trying to remember it.

Regards,

    Ed.

Posted using www.webuse.net