SED with back-references
by danielbmartin from LinuxQuestions.org on (#5CQZC)
This is a learning exercise.
Have: a large file of English words, one word on each line.
Want: a subset of the file where all words
meet these criteria ...
(1) have 6 letters
(2) letters 1 and 3 are the same
(3) no letters are repeated other than 1 and 3
This sed ...
Code:sed -nr "/^(.)(.)\1([^\1\2])([^\1\2\4])([^\1\2\4\5])$/p" \
<$WordList >$OutFile.. produces a file which contains words such as ...
Code:abacus
alarms
amazon
analog
apathy... which fit the criteria ...
... but also contains words such as ...
Code:avatar
acacia
bubble
cicada
cyclic... which do not fit criterion #3.
Please advise.
Daniel B. Martin
.


Have: a large file of English words, one word on each line.
Want: a subset of the file where all words
meet these criteria ...
(1) have 6 letters
(2) letters 1 and 3 are the same
(3) no letters are repeated other than 1 and 3
This sed ...
Code:sed -nr "/^(.)(.)\1([^\1\2])([^\1\2\4])([^\1\2\4\5])$/p" \
<$WordList >$OutFile.. produces a file which contains words such as ...
Code:abacus
alarms
amazon
analog
apathy... which fit the criteria ...
... but also contains words such as ...
Code:avatar
acacia
bubble
cicada
cyclic... which do not fit criterion #3.
Please advise.
Daniel B. Martin
.