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.

Here's what I do:

$ echo '1
2
3' | sed -n '
    x
    c\
test
    x
'
test
test
test

Is it expected behavior? I'm running gnu sed 4.2.1.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

excerpting from the info page: "output the lines of text which follow this command ... A new cycle is started after this command is done"

Presumably then, the last x command is never used.

share|improve this answer
    
+1 The fact is not mentioned in the man page. –  choroba Jun 6 at 11:47
    
Indeed, I was judging from man page. –  x-yuri Jun 6 at 11:51
    
A link to the manual would be apt: gnu.org/software/sed/manual/sed.html –  glenn jackman Jun 6 at 13:45
    
This behavior for the c command is also specified by POSIX: "Delete the pattern space. With a 0 or 1 address or at the end of a 2-address range, place text on the output and start the next cycle." –  jw013 Jun 6 at 14:07

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.