I cover horizontal and vertical match. The basic idea is to remove the spaces, and then use grep -f with the given list of words stored in the words file.
With grep -f results are displayed in a string. If you just want to see a consistent test, use grep -of .
Horizontal mapping
$ cat puzzle | tr -d ' ' | grep -f words alsfel gaanpl regela fneten $ cat puzzle | tr -d ' ' | grep -of words als gaan regel eten
Vertical mapping
To do this, you first need to transfer the contents of the file. For this, I use what I used for my other answer :
transpose () { awk '{for (i=1; i<=NF; i++) a[i,NR]=$i; max=(max<NF?NF:max)} END {for (i=1; i<=max; i++) {for (j=1; j<=NR; j++) printf "%s%s", a[i,j], (j<NR?OFS:ORS) } }' }
And let's see:
$ cat puzzle | transpose | tr -d ' ' | grep -f words jagerf slapen esafge tfndet lllkan $ cat puzzle | transpose | tr -d ' ' | grep -of words jager slapen af ge de kan
Then you can use rev (as you suggest in your question) for mirrored words. Also, tac can be interesting for vertically mirrored words.
Diagonal matching
For diagonal comparisons, I think an interesting approach would be to move each individual line a bit left / right. Thus,
exxxx xgxxx xxgxx
can be
exxxx gxxx gxx
and you can use vertical / horizontal approaches.
To do this, you can use printf , as described in Using variables in printf format :
$ cat a exxxx xgxxx xxgxx $ awk -vc=20 '{printf "%*s\n", c, $0; c-=2}' a exxxx xgxxx xxgxx