Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.
sed -e 's/72;/72, next_val = 0x11111111;/;/@/{h;s/test/next/g;x;G}'
fmt_vuln.c > fmt_vuln2.c

could you tell me about what is the meaning of ;/@/{h;s/test/next/g;x;G}?

share|improve this question

2 Answers 2

up vote 4 down vote accepted
;/@/{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.
share|improve this answer
    
totally solved my problem through your answer. thank you ^^ –  Thomas Kwon Nov 13 '13 at 13:07
/@/ # 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
}

So, for every line containing a @, the modified version of the pattern-space will be printed followed by the original (the hold-space contains the unmodified version).

see Command Summary for Sed

share|improve this answer
    
Thank you very much :) your answer is really helpful to me. ^^ –  Thomas Kwon Nov 13 '13 at 13:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.