nmh-workers
[Top] [All Lists]

Re: check if message is in a particular sequence?

2021-04-29 14:15:37
On Thu, 29 Apr 2021 12:49:40 -0400 Ken Hornstein <kenh(_at_)pobox(_dot_)com> 
sez:

What's the fastest/easiest way to check if a particular message
is a member of a particular sequence?

I thought I'd be able to compare the message number against the output
of "mark -list", but since sequences can be abbreviated with range
notation, that gets complicated quickly.  For example, message 6 is in
the sequence todo, but it's hard to tell from this:

You can get the expanded list of messages in a sequence by doing this:

      scan -format '%(msg)' sequence-name

I think from there, it's easy.  I do not know of a better way, but it
wouldn't surprise me if someone came up with something better.

I don't know that it's better, but my first thought was awk(1) to
parse the mark(1mh) sequence and search for the message number in
there.  It saves on filesystem access, but would suffer compared
with Ken's approach in that deleted messages would still be
reported -- which may or may not be what Paul wants.  Also, I'm
making assumptions about mark(1mh)'s output format, which is
wholly unnecessary (and more brittle than) if you use scan(1mh).

Checking for message # 6:

     $ echo 'todo: 1 3 5-8 13 16 46 49 52-53' | awk -v MY_MSG=6 -v RS=" " 
'BEGIN{missing=1;} /^[0-9]+$/{if (MY_MSG==$0) {missing=0; print "in sequence 
entry"}} /^[0-9]+-[0-9]+$/{split($0,ss,"-"); if (MY_MSG>=ss[1] && 
MY_MSG<=ss[2]) {missing=0; print "in sequence range"}} END{if (missing) print 
"not in sequence"}'
     in sequence range

Checking for message # 49:

     $ echo 'todo: 1 3 5-8 13 16 46 49 52-53' | awk -v MY_MSG=49 -v RS=" " 
'BEGIN{missing=1;} /^[0-9]+$/{if (MY_MSG==$0) {missing=0; print "in sequence 
entry"}} /^[0-9]+-[0-9]+$/{split($0,ss,"-"); if (MY_MSG>=ss[1] && 
MY_MSG<=ss[2]) {missing=0; print "in sequence range"}} END{if (missing) print 
"not in sequence"}'
     in sequence entry

Checking for (out-of-sequence) message # 99:

     $ echo 'todo: 1 3 5-8 13 16 46 49 52-53' | awk -v MY_MSG=99 -v RS=" " 
'BEGIN{missing=1;} /^[0-9]+$/{if (MY_MSG==$0) {missing=0; print "in sequence 
entry"}} /^[0-9]+-[0-9]+$/{split($0,ss,"-"); if (MY_MSG>=ss[1] && 
MY_MSG<=ss[2]) {missing=0; print "in sequence range"}} END{if (missing) print 
"not in sequence"}'
     not in sequence

                                Bob

<Prev in Thread] Current Thread [Next in Thread>