이 sed 명령의 의미는 무엇입니까 :`; / @ / {h; s / test / next / g; x; G}`? = 0x11111111;/;/@/{h;s/test/next/g;x;G}’ fmt_vuln.c >

sed -e 's/72;/72, next_val = 0x11111111;/;/@/{h;s/test/next/g;x;G}'
fmt_vuln.c > fmt_vuln2.c

무슨 의미인지 말씀해 주 ;/@/{h;s/test/next/g;x;G}시겠습니까?



답변

;/@/{h;s/test/next/g;x;G}?

/@/  search for an `@` sign
{}   for the lines where that is true do this 'block' of code
h    put the pattern match in the hold space
s/   substitute test for next everywhere in the space
g    do the previous substitution for all matches on the line
x    swap the hold with the pattern space
G    Add a new line with the contents of the hold space.

답변

/@/ # For pattern-space containing the character @ do the following
{
  h              # place a copy of the pattern-space into the hold-space
  s/test/next/g  # replace all instances of "test" with "next" in the pattern-space
  x              # swap the pattern-space with the hold-space
  G              # append a newline followed by contents of hold-space to the pattern-space
}

따라서 @을 포함하는 모든 행에 대해 수정 된 버전의 패턴 공간이 인쇄 된 다음 원본이 인쇄됩니다 (보유 공간에는 수정되지 않은 버전이 포함됨).

Sed의 명령 요약 참조