[ ] Tuesday, 18 January 2022 [ ]

grep

Using grep to find words of a specific length, can be done in a number of ways. grep -E '^[[:alpha:]]{4}$' file grep -E '^[A-Za-z]{4}$' file grep -E '^.{4}$' file grep -E '^....$' file grep '^....$' file grep '^.\{4\}$' file The examples above all give the same results. Using -E option makes the pattern be interpreted as an extended regular expression, thus grep behaves as egrep. It the last example the braces need to be escaped otherwise it would be a literal match on .{4}

echo '.{4}' | grep '^.{4}$'
.{4}

The dictionary files can be found /usr/share/dict/

grepdict


$Id: diary,v 1.38 2025/01/01 22:43:54 fred Exp $