Computer Old Farts Forum
 help / color / mirror / Atom feed
From: Ralph Corderoy <ralph@inputplus.co.uk>
To: coff@tuhs.org
Subject: [COFF] Re: Grep has gone overboard
Date: Mon, 30 May 2022 09:01:29 +0100	[thread overview]
Message-ID: <20220530080129.BDA1521F8A@orac.inputplus.co.uk> (raw)
In-Reply-To: <0a704531-b12d-42ff-b82c-5af5d935bf1a@home.arpa>

Hi Michael,

> I was trying to do something very similar using procmail regexes some
> time ago, only with strings instead of individual characters (for
> parsing and matching on arbitrarily-ordered, comma-separated values
> within a header).  I never did come up with a good solution.

Assuming procmail has BRE, this does one interpretation of what you
said.

    $ grep '^ *field *: *\(foo\|bar\|xyzzy\)\( *, *\(foo\|bar\|xyzzy\)\)* *$' <<\E
    > otherfield: foo
    > field:
    > field: ,
    > field:foo
    > field : foo
    > field:xyzzy
    > field: xyzzy,bar, foo , xyzzy
    > field: xyzzy,bar, foo , xyzzy ,
    > E
    field:foo
    field : foo
    field:xyzzy
    field: xyzzy,bar, foo , xyzzy
    $

If I was doing it in sed, I'd s/$/,/ before and s/,$// after so the list
of alternatives need only be given once with each alternative having to
be followed by a comma, i.e. the comma switches from separator to
terminator.

-- 
Cheers, Ralph.

  parent reply	other threads:[~2022-05-30  8:01 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-30  4:12 [COFF] " Dave Horsfall
2022-05-30  4:47 ` [COFF] " Bakul Shah
2022-05-30  6:35   ` Michael Kjörling
2022-05-30  6:51     ` Bakul Shah
2022-05-30  8:26       ` Ralph Corderoy
2022-05-30  8:01     ` Ralph Corderoy [this message]
2022-05-30  8:16   ` Ralph Corderoy
2022-05-30  8:43     ` Bakul Shah
2022-05-30  9:19       ` Ralph Corderoy
2022-05-30  7:38 ` Ralph Corderoy
2022-05-30  7:44   ` Ralph Corderoy

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=20220530080129.BDA1521F8A@orac.inputplus.co.uk \
    --to=ralph@inputplus.co.uk \
    --cc=coff@tuhs.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).