Hi,

I wrote:
>     $ scan -width 0 -format '%(msg) %(decode{subject})' +. |
>     > awk '{m=$1; sub(/[^ ]* /, "", $0)} NR>1 && $0==l {print m} {l=$0}'
>     2
>     3
>     $
>
> And that one-line awk above, as I originally wrote it, re-formatted to
> be a usable script, i.e. chmod +x, is
>
>     #! /usr/bin/awk -f
>
>                        { m = $1;  sub(/[^ ]* /, "", $0) }
>     NR > 1 && $0 == l  { print m }
>                        { l = $0 }
>
> It would be interesting to see the length of a functionally equivalent
> Python version as a lot of what awk makes implicit is tedious code in
> many other languages and requires much more comprehension for
> non-programmers, e.g. method functions of an object, context objects,
> etc.

    #! /usr/bin/python

    import sys

    paths = sys.argv[1:]
    if not paths:
        paths = ['/dev/stdin']

    nr = 0
    for path in paths:
        with open(path) as f:
            for l in f:
                nr += 1
                m, l = l.split(' ', 1)
                if nr > 1 and l == prev:
                    print(m)
                prev = l

-- 
Cheers, Ralph.

-- 
  Next meeting: Online, Jitsi, Tuesday, 2020-06-02 20:00
  Check to whom you are replying
  Meetings, mailing list, IRC, ...  http://dorset.lug.org.uk
  New thread, don't hijack:  mailto:dorset@mailman.lug.org.uk

Reply via email to