2

Another one I can't seem to solve : all greek letters with 5 unique letters (meaning that each letter only appears once).

my solution :

egrep '(.)([^/1])([^/1/2])([^/1/2/3])([^/1/2/3/4])' greek.txt

So What I think I am saying :

  • match any first character

  • every consecutive character can't be any of the previous patterns

But what comes out :

alpha
gamma
delta
epsilon
theta
kappa
lambda
omicron
sigma
upsilon
omega

Alpha, gamma, they have characters that are not unique. Any hints or tips on what I am doing wrong ?

2
  • Use one grep to filter all lines with length != 5.
  • Use the second grep to filter all words, where any character repeats.

egrep '^.{5}$' greek.txt | egrep -v '^.*(.).*\1.*$'

Thanks to @StephaneChazelas for pointing out optimizations in a comment:

grep -x '.\{5\}' | grep -v '\(.\).*\1'

1
  • 1
    Note that egrep is not required to support backreferences (traditional implementations don't). grep is. So grep -x '.\{5\}' | grep -v '\(.\).*\1' Aug 17 '15 at 12:55
1

I think you're on the right track but got your slashes going to wrong direction to be back-references. Use \1 not /1!

4
  • 1
    still not working unfortunately :( Aug 8 '11 at 13:24
  • 1
    [^\1] is any character but backslash and 1. You can't use back references like that (egrep is not meant to support backreferences at all anyway) Aug 17 '15 at 13:00
  • @StéphaneChazelas : I only ever remember seeing egrep implemented as a wrapper script for 'grep -E', and was not aware, that it isn't supposed to support backreferences. OP had used egrep, so I just went with that. Aug 17 '15 at 18:22
  • egrep was originally written as a separate utility using a different algorithm. egrep didn't have backreferences because they don't belong in a true regular expressions working with finite automatons. It was POSIX introducing -E/-F to merge grep/egrep/fgrep, but that was only a UI change, POSIX EREs still don't support back references. For GNU grep, BRE and ERE are the same, the difference is only in the syntax (so backreferences are supported there, but again they can't be used like that). Aug 17 '15 at 19:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.