Path: csiph.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!bofh.it!news.nic.it!robomod From: Greg Wooledge Newsgroups: linux.debian.user Subject: Re: Useless use of shell pipelines [was: Useful use of dd] Date: Sat, 03 Jul 2021 15:40:01 +0200 Message-ID: References: X-Mailbox-Line: From debian-user-request@lists.debian.org Sat Jul 3 13:34:27 2021 Old-Return-Path: X-Amavis-Spam-Status: No, score=-5.207 tagged_above=-10000 required=5.3 tests=[BAYES_00=-2, DIGITS_LETTERS=1, LDO_WHITELIST=-5, RDNS_NONE=0.793] autolearn=no autolearn_force=no X-Policyd-Weight: using cached result; rate: -4.6 Mail-Followup-To: debian-user@lists.debian.org MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit X-Mailing-List: archive/latest/777410 List-ID: List-URL: List-Archive: https://lists.debian.org/msgid-search/YOBnUMNFekHhpq63@wooledge.org Approved: robomod@news.nic.it Lines: 31 Organization: linux.* mail to news gateway Sender: robomod@news.nic.it X-Original-Date: Sat, 3 Jul 2021 09:34:08 -0400 X-Original-Message-ID: X-Original-References: <4ef539b6-af04-4d53-9512-cd3dba0d4ce3@gmx.com> <20210702025528.GA14316@axis.corp> <87im1ts27c.fsf@iki.fi> <20210702074923.GA9613@tuxteam.de> Xref: csiph.com linux.debian.user:236802 On Sat, Jul 03, 2021 at 10:23:39AM +0200, l0f4r0@tuta.io wrote: > 2 juil. 2021, 23:30 de dpchrist@holgerdanske.com: > > $ cat useless-use-of-grep > > This is the first line: bla bla bla. > > This is line xxxx: bla bla bla. > > This is the last line: bla bla bla. > Here is a better `sed` if you want a all-in-one:  > sed -n /xxxx/{s/bla/foo/p} useless-use-of-grep Also: awk '/xxxx/{sub("bla", "foo"); print}' useless-use-of-grep > > $ time for n in {1..10000}; do perl -ne 's/bla/foo/ && print if /xxxx/' useless-use-of-grep > /dev/null; done > > > > real 0m23.624s > > user 0m14.308s > > sys 0m10.826s > I'm not in front of my Linux terminal, can someone launch the `time` command for my `sed` above please ? :) unicorn:~$ time for n in {1..10000}; do perl -ne 's/bla/foo/ && print if /xxxx/' useless-use-of-grep; done >/dev/null real 16.034 user 11.555 sys 4.847 unicorn:~$ time for n in {1..10000}; do sed -n '/xxxx/{s/bla/foo/p}' useless-use-of-grep; done >/dev/null real 11.489 user 8.670 sys 3.251 unicorn:~$ time for n in {1..10000}; do awk '/xxxx/{sub("bla", "foo"); print}' useless-use-of-grep; done >/dev/null real 15.690 user 11.575 sys 4.532 Sed wins this particular race, not surprisingly.