From: Amavect <amavect@gmail.com>
To: 9front@9front.org
Subject: Re: [9front] [PATCH] Kill, kill, slay: banish sed, long live awk!
Date: Sun, 2 Jul 2023 11:17:46 -0500 [thread overview]
Message-ID: <CAGOW0YNmtzBAhYMx66Dhkdfszq1cBZALqup6h3GHCCK-tTbTRQ@mail.gmail.com> (raw)
In-Reply-To: <10b09e19-27ed-495d-82b5-9c79240b8ccb@sirjofri.de>
On Sun, Jul 2, 2023 at 2:46 AM sirjofri <sirjofri+ml-9front@sirjofri.de> wrote:
>
> Hello,
>
> out of curiosity, why s/sed/awk? What's wrong about sed?
>
> sirjofri
The command line arguments are passed to sed through a sed expression,
so the program name is parsed as a sed expression and not as a string.
This affects program names with a dot (6.out).
In practice, this almost never results in name conflicts,
so the real reason is that I find the sed version hard to read.
For fun, I rewrote the sed version, which makes the command generation obvious:
ps | sed -n '/^'$user' .* '$i'$/s%[^ ]* *([0-9]+) .* (.*)$%@{echo
kill>/proc/\1/note} # \2%p'
Compare to the original:
ps | sed -n '/^'$user' .* '$i'$/s%[^ ]* *%~>/proc/%s% *.*
(.*)%/note} # \1%s%~%@{echo kill%p'
Compare to awk:
ps | awk -v 'user='$user -v 'prog='$i '$1 == user && $7 == prog {print
"@{echo kill>/proc/" $2 "/note} # " $7}'
Thanks,
Amavect
next prev parent reply other threads:[~2023-07-02 17:22 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-02 1:44 Amavect
2023-07-02 7:43 ` sirjofri
2023-07-02 16:17 ` Amavect [this message]
2023-07-02 18:32 ` Stuart Morrow
2023-07-02 21:01 ` Steve Simon
2023-07-03 22:46 ` Stuart Morrow
2023-08-01 5:36 ` mkf9
2023-08-01 22:10 ` [9front] Kill, kill, slay: banish sed, long live awk: Now historic plan9 Steve Simon
2023-08-02 4:56 ` Roberto E. Vargas Caballero
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAGOW0YNmtzBAhYMx66Dhkdfszq1cBZALqup6h3GHCCK-tTbTRQ@mail.gmail.com \
--to=amavect@gmail.com \
--cc=9front@9front.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).