ความหมายของคำสั่ง sed นี้คืออะไร: `; / @ / {h; s / test / next / g; x; G}`


คำตอบ:


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.

แก้ปัญหาทั้งหมดของฉันผ่านคำตอบของคุณ ขอบคุณ ^^
โทมัสควอน

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
}

ดังนั้นสำหรับทุกบรรทัดที่มี @ เวอร์ชันที่แก้ไขของ pattern-space จะถูกพิมพ์ตามด้วยต้นฉบับ (hold-space มีเวอร์ชันที่ไม่ได้แก้ไข)

ดูสรุปคำสั่งสำหรับ Sed


ขอบคุณมาก :) คำตอบของคุณเป็นประโยชน์กับฉันจริงๆ ^^
โทมัสควอน
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.