grep -i “^ (.). * \ 1 $” sowpods.txt output.txt

0

Estou usando uma lista de palavras scrabble que eu baixei chamada "sowpods.txt" e estou tentando usar o grep para encontrar todas as palavras com esses critérios.

  • palavra de 7 letras
  • Começa e termina com a mesma letra
  • Tem a mesma segunda, quarta e sexta letra
  • tem uma terceira e quinta carta diferente

A linha que eu tenho até agora está me dando um erro de referência, então eu tentei usar guias on-line, mas eles eram insanamente confusos. Isso é possível? Se assim poderia alguém por favor me ajude? Obrigado !!!

Eu também estou em um mac e estou usando o terminal padrão.

    
por Kappa123 15.10.2018 / 06:59

1 resposta

1

Usando a opção -P (PCRE), se disponível em seu sistema:

grep -P '^(?=[a-zA-Z]{7}$)(.)(?!)(.)(?!)(?!)(.)(?!)(?!)(?!).$' inputfile

Explicação:

^
  (?=[a-zA-Z]{7}$)  : positive lookahead, zero-length assertion that make sure we have exactly 7 letters. You may use \pL{7} if you want to deal with any laguage
  (.)               : first letter, captured in group 1
  (?!)            : negative lookahead, zero-length assertion that make sure we don't have the same letter as in group 1 after
  (.)               : second letter, captured in group 2
  (?!)            : negative lookahead, zero-length assertion that make sure we don't have the same letter as in group 1 after
  (?!)            : negative lookahead, zero-length assertion that make sure we don't have the same letter as in group 2 after
  (.)               : third letter, captured in group 3
                  : fourth letter == second letter
  (?!)            : negative lookahead, zero-length assertion that make sure we don't have the same letter as in group 1 after
  (?!)            : negative lookahead, zero-length assertion that make sure we don't have the same letter as in group 2 after
  (?!)            : negative lookahead, zero-length assertion that make sure we don't have the same letter as in group 3 after
  .                 : fifth letter
                  : sixth letter == second letter
                  : seventh letter == first letter
$

DEMONSTRAÇÃO

    
por 15.10.2018 / 12:29