sed命令的含义是什么:`; / @ / {h; s / test / next / g; x; G}`?


9
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}吗?

Answers:


6
;/@/{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.

通过您的回答完全解决了我的问题。谢谢^^
Thomas Kwon

6
/@/ # 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的命令摘要


非常感谢您:)您的回答对我真的很有帮助。^^
Thomas Kwon
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.