RE 오류: osx sed에서 반복 연산자 피연산자가 유효하지 않습니다.

RE 오류: osx sed에서 반복 연산자 피연산자가 유효하지 않습니다.

Ubuntu debian에서 osx로 sed 스크립트를 복사했지만

RE 오류: 잘못된 반복 연산자 피연산자

뭐가 문제 야?

$ . sed_shorter_version_user_extensions_to_ruby.sh
sed: 22: "
### DELETE whole lines ...": RE error: repetition-operator operand invalid
Inspecting 1 file...
...

스크립트는 다음과 같습니다. (22가 22행을 의미하는 경우에는 행 번호를 남겨 두었습니다).

  1 sed '
  2 ### DELETE whole lines
  3 /\/\//d
  4 /^$/d
  5 ### CHANGE large chunks
  6 s/^storedVars\["/  def /
  7 s/SAD/sad/
  8 s/HAPPY/happy/
  9 s/"\][[:space:]]*=[[:space:]]*/\
 10     /
 11 s/;/\
 12   end\
 13 /
 14 ### CHANGE small chunks
 15 s/"css=/"/
 16 s/"link=/"/
 17 s/"label=/"/
 18 ### CHANGE specific lines
 19 ### Scoped corrections for clarity
 20 /def insurance_expiration/ {
 21   /expiration_month/ {
 22     s/"value=.*\+1)/"(Date.new + 1.month).strftime(%B)"/
 23   }
 24   /expiration_year/ {
 25     s/"value=.*FullYear())/"(Date.new + 1.month).strftime(%Y)"/
 26   }
 27 }
 28 ### Unable to combine these for the %B and %Y despite several tries mdd 9/13/2015
 29 /Date.*new.*month/ {
 30   s/"//g
 31   s/%B/"%B"/
 32   s/%Y/"%Y"/
 33 }
 34 /choose_submodel_text/ {
 35   s/" \] =/\n    /
 36 }
 37 /email.*albert.*random/ {
 38   s/("albert.*gmail\.com")/Faker::Internet.email/
 39 }
 40 ' Variables/user-extensions.js | awk '
 41 ### ADD Header and footer
 42 BEGIN { print "# page object methods"; print "module PageObject # Variable values" }
 43       { print }
 44 END { print "end" } '> rspec_conversions/new_page_object_methods.rb
 45 rubocop -a rspec_conversions/new_page_object_methods.rb

답변1

s/"value=.*\+1)/"(Date.new + 1.month).strftime(%B)"/
          ^^^

*연산자가 0번 이상 반복되고 그 뒤에 가 있습니다 \+. 의 의미는 \+sed 버전에 따라 다릅니다. +또는 와 일치할 수도 \+있고 하나 이상의 반복 연산자일 수도 있습니다. GNU sed는 \+여기와 같이 의미가 없는 상황을 제외하고 이것을 하나 이상의 반복 연산자로 처리합니다. 내 생각에 OSX sed는 \+이것을 하나 이상의 반복 연산자로 취급하고 두 개의 연속된 반복 연산자가 의미가 없기 때문에 여기서 불평한다고 생각합니다.

sed에서 일치 +하려면 +.

1 글쎄요, 말이 되지만 반복 연산자를 제외한 모든 시퀀스는 {…}단일 시퀀스로 축소될 수 있으므로 대부분의 정규식 엔진은 이를 특별하게 처리합니다.

관련 정보