I recently had a curiosity about words in the dictionary that share both "pro-" and "con-" as a prefix. So, for example, procession/concession, produce/conduce, profess/confess, progress/congress, and so on. I'm basically looking for any words that match both
^con(.+)$, where the content of the capture group is the same.
My initial caveman command was:
sed -nr 's/^con(.+)$/\1/Ip' /usr/share/dict/words | \ xargs -I SUFFIX -n1 grep -i '^proSUFFIX$' /usr/share/dict/words
It seems to work, outputting a full "con-" word as long as there exists a matching "pro-" word. Problem is, it's slooow. It invokes
grep for every potential match, asking it to scan the whole dictionary each time. I could speed it up by making a temporary file that only has pro/con words in it, but it feels like there must be some efficient way to do this without writing a file.
Is there a tool in the GNU world that's well suited to this kind of intersection search?