[Discuss] Please help with a BASH puzzle

Dale R. Worley worley at alum.mit.edu
Fri Aug 30 21:50:49 EDT 2019


discuss-request at blu.org writes:
> From: Bill Horne <bill at horne.net>

> I'm trying to do something that should be very easy to do, and yet I 
> can't remember how to do it, and I'm asking for help.
>
> I have an alpha-numeric, sorted file, that looks like this:

> I'm trying to remember what BASH utility, script, or? command would flag 
> the missing value (in this case, "01AD").

Of course, the hard part is doing it without materializing the list of
all possible words with which you want to compare your file.

    # Input a series of lines containing one word each and output each word
    # extended in all possible ways by one character out of an ordered alphabet.
    # In this example, the alphabet is 0, 1, 2, and 3.
    function extend () {
        while read WORD
        do
            echo ${WORD}0
            echo ${WORD}1
            echo ${WORD}2
            echo ${WORD}3
        done
    }

    # Compare the complete list of 3-letter words with the file "sample".
    comm -13 sample <( echo | extend | extend | extend )

Dale


More information about the Discuss mailing list