[Discuss] Please help with a BASH puzzle

Bill Ricker bill.n1vux at gmail.com
Fri Aug 23 23:56:41 EDT 2019


On Fri, Aug 23, 2019 at 11:05 PM Chris Tyler <chris at tylers.info> wrote:

> This will generate a "complete" file (36^4 = 1.6 million lines, 8.1 MB) in
> bash:
>
>    a="{$(echo {0..9} {A..Z}|tr " " ,)}"; eval echo $a$a$a$a | tr " " "\012"
> >/tmp/all
>
> ...Which you can then compare your input file against using the comm
> command. (It runs in <5s on my chromebook here).


... and if you don't want to save it to disk, you can wrap it to stream
both inputs on pipe-like file-descriptors as previously described -

(export LC_ALL=C; comm -23 <( a="{$(echo {0..9} {A..Z}|tr " " ,)}"; eval
echo $a$a$a$a | tr " " "\012")   $inputfile)

(8MB isn't a large file these days ... but if the real data is wider ...
and thus both files exponentially larger ... might want a more streaming
generator )


More information about the Discuss mailing list