LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Choosing words based on letter count (https://www.linuxquestions.org/questions/programming-9/choosing-words-based-on-letter-count-929144/)

millgates 02-15-2012 01:34 PM

Quote:

Originally Posted by danielbmartin (Post 4603089)
Code:

# Find words which contain
# at least 3 of the same character.
# Use sed to mimic grep.
cat < $WrdLst                    \
|sed -n '/\(.\).*\1.*\1/p'      \
> $Work09


You're almost there. The problem is the 'p' command will not modify the matching line.
You can combine it with 's', though.

Code:

sed -n 's/.*\(.\).*\1.*\1/\1 &/p'
where I used '&' to reference the entire matched expression. I also had to add a '.*' at the begining of my regex to match the begining of the word.

danielbmartin 02-15-2012 03:07 PM

Quote:

Originally Posted by millgates (Post 4603264)
Code:

sed -n 's/.*\(.\).*\1.*\1/\1 &/p'

Another home run for millgates! I hope you enjoy solving these character-string brain teasers. Thank you!

Daniel B. Martin


All times are GMT -5. The time now is 08:46 AM.