User Tools

Site Tools


remove_lines_with_duplicate_letters

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
remove_lines_with_duplicate_letters [2023/08/11 14:40] – ↷ Page name changed from remove_lines_duplicate_letters to remove_lines_with_duplicate_letters rajuremove_lines_with_duplicate_letters [2023/08/27 23:48] (current) raju
Line 3: Line 3:
 Find five letter words that are made up of letters {h, i, k, e, r, s} where each letter appears only once. Find five letter words that are made up of letters {h, i, k, e, r, s} where each letter appears only once.
 ==== Issue ==== ==== Issue ====
-If we do 
 <code> <code>
-grep -"^[hikers][hikers][hikers][hikers][hikers]$" /usr/share/dict/american-english +grep -Ei "^[hikers]{5}$" /usr/share/dict/american-english 
-<code> +</code> 
-shows+gives
 <code> <code>
 Essie Essie
Line 17: Line 16:
 ... ...
 </code> </code>
-some of the words have the letters duplicated. For example, in 'Irish' the letter 'i' is repeated twice. Such words should be filtered out.+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 ==== ==== Solution ====
 +Pipe the output to ''grep -viE '(.).*\1' ''. For example
 +
 <code> <code>
- % grep -"^[hikers][hikers][hikers][hikers][hikers]$" /usr/share/dict/american-english | grep -viE '(.).*\1+% grep -Ei "^[hikers]{5}$" /usr/share/dict/american-english | grep -viE "(.).*\1"
 Sheri Sheri
 Shrek Shrek
Line 32: Line 34:
 skier skier
 </code> </code>
 +
 +==== Ref ====
 +  * https://unix.stackexchange.com/questions/352927/delete-all-lines-that-contain-duplicate-letters -> comment by Stéphane Chazelas
 +    * I got the idea from here.
 +  * (Mastering Regular Expressions, Jeffrey E.F. Friedl, 2006) book -> Chapter 1 "Introduction to Regular Expressions" -> section "Parentheses and Backreferences" -> pages 20 through 22 go over this concept.
 +
  
remove_lines_with_duplicate_letters.1691764807.txt.gz · Last modified: 2023/08/11 14:40 by raju