egrep 주문이 잘못되었습니다

egrep 주문이 잘못되었습니다

이것은 스크립트의 일부입니다. 첫 번째 단어에 문자열이 두 번 이상 있는지, 마지막 단어(마지막 단어의 한 줄)에 두 번 이상 있는지 확인하는 부분입니다. .

echo "$first $last" | egrep "(([^ ]+)[^ ]* \1[^ ]* )[ ]* \2\2 * "

오류는 다음과 같습니다

egrep: Invalid back reference

답변1

표현을 풀어보세요:

NODE                     EXPLANATION
--------------------------------------------------------------------------------
  (                        group and capture to \1:
--------------------------------------------------------------------------------
    (                        group and capture to \2:
--------------------------------------------------------------------------------
      [^ ]+                    any character except: ' ' (1 or more
                               times (matching the most amount
                               possible))
--------------------------------------------------------------------------------
    )                        end of \2
--------------------------------------------------------------------------------
    [^ ]*                    any character except: ' ' (0 or more
                             times (matching the most amount
                             possible))
--------------------------------------------------------------------------------
                             ' '
--------------------------------------------------------------------------------
    \1                       what was matched by capture \1
--------------------------------------------------------------------------------
    [^ ]*                    any character except: ' ' (0 or more
                             times (matching the most amount
                             possible))
--------------------------------------------------------------------------------
                             ' '
--------------------------------------------------------------------------------
  )                        end of \1
--------------------------------------------------------------------------------
  [ ]*                     any character of: ' ' (0 or more times
                           (matching the most amount possible))
--------------------------------------------------------------------------------
                           ' '
--------------------------------------------------------------------------------
  \2                       what was matched by capture \2
--------------------------------------------------------------------------------
  \2                       what was matched by capture \2
--------------------------------------------------------------------------------
   *                       ' ' (0 or more times (matching the most
                           amount possible))

\1캡처된 내용의 정의가 완료되기 \1전에 참조 하려는 것으로 보입니다 .

관련 정보