>Synopsis:      sed c command doesn't "start the next cycle"
>Category:      user
>Environment:
        System      : OpenBSD 5.3
        Details     : OpenBSD 5.3 (GENERIC.MP) #58: Tue Mar 12 18:43:53 MDT 2013
                         
[email protected]:/usr/src/sys/arch/i386/compile/GENERIC.MP

        Architecture: OpenBSD.i386
        Machine     : i386
>Description:
        The POSIX standard at
        
         http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html
        
        states that the sed command
        
         c\
         text
        
        will "place text on the output and start the next cycle."  But
        OpenBSD's implementation of sed does not start the next
        processing cycle in this case.

>How-To-Repeat:
        Place the following sed script in the file script.txt
        
         1h
         2c\
         mytext
         2x
        
        then, according to the POSIX standard, the command
        
         printf 'line1\nline2\nline3\n' | sed -f script.txt
        
        should output
        
         line1
         mytext
         line3
        
        Notice that after executing the c command, sed starts the next
        processing cycle (for line3) at the top of the script, skipping
        execution of the x command.  But OpenBSD produces the following
        output
        
         line1
         mytext
         line1
         line3
        
        because OpenBSD's sed executes the x command immediately after
        executing the c command.  This violates the POSIX standard.

>Fix:
        This bug has a simple one-line fix.  See
        
         http://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=45981
        
        The sed man page should also be updated to document this change.

Reply via email to