remove_lines_with_duplicate_letters
This is an old revision of the document!
Table of Contents
Remove lines with duplicate letters
Task
Find five letter words that are made up of letters {h, i, k, e, r, s} where each letter appears only once.
Issue
grep -i "^[hikers][hikers][hikers][hikers][hikers]$" /usr/share/dict/american-english
gives
Essie Hesse Irish Kerri Reese Sheri ...
where some letters are duplicated in some of the words. For example, the letter 'i' appears twice in the word 'Irish'. We need to filter out all such words.
Solution
Pipe the output to grep -viE '(.).*\1'
. For example
% grep -i "^[hikers][hikers][hikers][hikers][hikers]$" /usr/share/dict/american-english | grep -viE '(.).*\1' Sheri Shrek heirs hiker hikes hires sheik shire shirk skier
remove_lines_with_duplicate_letters.1691765175.txt.gz · Last modified: 2023/08/11 14:46 by raju