GNU bug report logs - #31781
I apologize it's not the right place, but I need answer

Previous Next

Package: sed;

Reported by: Budi <budikusasi <at> gmail.com>

Date: Sun, 10 Jun 2018 22:59:01 UTC

Severity: normal

Tags: notabug

Done: Assaf Gordon <assafgordon <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 31781 in the body.
You can then email your comments to 31781 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-sed <at> gnu.org:
bug#31781; Package sed. (Sun, 10 Jun 2018 22:59:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Budi <budikusasi <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-sed <at> gnu.org. (Sun, 10 Jun 2018 22:59:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Budi <budikusasi <at> gmail.com>
To: bug-sed <at> gnu.org
Subject: I apologize it's not the right place, but I need answer
Date: Mon, 11 Jun 2018 05:58:44 +0700
[Message part 1 (text/plain, inline)]
​How to use SED command(s) that will replace the shell's pipe command in
order to perform more efficient, e.g:

echo abcde​ | sed -r 's/cd/XX/' | sed 's/[^x]/z/ig'

become far more efficient and compact, might be look like this,

echo abcde​ | sed -r 's/cd/XX/ {N: s/ ...........    }

( ...so on. That's what I am asking for )

both will give the same result   zzXXz
[Message part 2 (text/html, inline)]

Added tag(s) notabug. Request was from Assaf Gordon <assafgordon <at> gmail.com> to control <at> debbugs.gnu.org. (Tue, 12 Jun 2018 09:05:02 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 31781 <at> debbugs.gnu.org and Budi <budikusasi <at> gmail.com> Request was from Assaf Gordon <assafgordon <at> gmail.com> to control <at> debbugs.gnu.org. (Tue, 12 Jun 2018 09:05:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-sed <at> gnu.org:
bug#31781; Package sed. (Tue, 12 Jun 2018 09:05:02 GMT) Full text and rfc822 format available.

Message #12 received at 31781-done <at> debbugs.gnu.org (full text, mbox):

From: Assaf Gordon <assafgordon <at> gmail.com>
To: Budi <budikusasi <at> gmail.com>, 31781-done <at> debbugs.gnu.org
Subject: Re: bug#31781: I apologize it's not the right place, but I need answer
Date: Tue, 12 Jun 2018 03:04:21 -0600
tags 31781 notabug
close 31781
stop

Hello,

On 10/06/18 04:58 PM, Budi wrote:
> ​How to use SED command(s) that will replace the shell's pipe command in
> order to perform more efficient, e.g:
> 
> echo abcde​ | sed -r 's/cd/XX/' | sed 's/[^x]/z/ig'
> 
> become far more efficient and compact, might be look like this,
> 
> echo abcde​ | sed -r 's/cd/XX/ {N: s/ ...........    }
> 
> ( ...so on. That's what I am asking for )
> 
> both will give the same result   zzXXz
> 

The portable way is to use multiple "-e" parameters:

  $ echo abcde​ | sed -e 's/cd/XX/' -e 's/[^x]/z/ig'
  zzXXzz

That should work on all sed, not just gnu sed.

When using GNU sed, you can specify multiple commands
separated by semicolons:

  $ echo abcde​ | sed 's/cd/XX/ ;  s/[^x]/z/ig'
  zzXXzz


I'm closing this item but discussion can continue by replying
to this thread.

regards,
 - assaf




Information forwarded to bug-sed <at> gnu.org:
bug#31781; Package sed. (Tue, 12 Jun 2018 11:28:02 GMT) Full text and rfc822 format available.

Message #15 received at 31781-done <at> debbugs.gnu.org (full text, mbox):

From: Eric Blake <eblake <at> redhat.com>
To: Assaf Gordon <assafgordon <at> gmail.com>, Budi <budikusasi <at> gmail.com>,
 31781-done <at> debbugs.gnu.org
Subject: Re: bug#31781: I apologize it's not the right place, but I need answer
Date: Tue, 12 Jun 2018 06:27:31 -0500
On 06/12/2018 04:04 AM, Assaf Gordon wrote:
>> ​How to use SED command(s) that will replace the shell's pipe command in
>> order to perform more efficient, e.g:
>>
>> echo abcde​ | sed -r 's/cd/XX/' | sed 's/[^x]/z/ig'

Many times, it IS possible to use a single sed process instead of a 
pipeline of two consecutive sed processes, or to turn 'grep ... | sed 
...' into a single sed process.  But this is not universally true - 
there are some cases where pipelining two sed processes together is 
required (where no single sed process will accomplish the same task). 
So, there is no generic way to rewrite a sed pipeline into a single script.

For an example, typical configure scripts produced by Autoconf include 
this pipeline, including the comment:

  # Blame Lee E. McMahon (1931-1989) for sed's syntax.  :-)
  sed -n '
    p
    /[$]LINENO/=
  ' <$as_myself |
    sed '
      s/[$]LINENO.*/&-/
      t lineno
      b
      :lineno
      N
      :loop
      s/[$]LINENO\([^'$as_cr_alnum'_].*\n\)\(.*\)/\2\1\2/
      t loop
      s/-\n.*//
    ' >$as_me.lineno

There is NO WAY to rewrite that into a single sed process (the first 
process prints every line and also appends a line number line any time 
literal '$LINENO' was seen; the second process then folds the line 
numbers in place of the '$LINENO' occurrences).  But then again, that 
second use of sed is much more involved than your typical one-liner 
substitution.

> 
> The portable way is to use multiple "-e" parameters:
> 
>    $ echo abcde​ | sed -e 's/cd/XX/' -e 's/[^x]/z/ig'
>    zzXXzz
> 
> That should work on all sed, not just gnu sed.

Yes, when combining two one-liner substitutions that both operate on 
every line, that should work.  But once the sed script gets more 
involved, such as using 'sed -n' with 's///p' or using addresses to 
limit which lines are acted on, you have to be sure that the second half 
of your rewrite only performs in the same cases where it would get 
output from the first half when it was two separate processes.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 11 Jul 2018 11:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 6 years and 339 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.