inconsistent behavior of sed

Mark Lomas tmal at cl.cam.ac.uk
Wed Jul 12 22:39:25 AEST 1989


In article <377 at proexam.UUCP> glen at proexam.UUCP (Glen Brydon) writes:
>	sed 's/.*/&/p;d'  (this is a minimal condensation)
>
>It seems obvious to me that this should simply pass all information,
>however, some versions of sed actually delete. This seems to be always
>true of sysV sed and recently true of bsd sed (post 4.0 sunOS).

The manual entry for sed which is supplied with HP-UX, a System V
derivative, indicates that this change in behaviour is deliberate.

In previous versions of sed the `p' flag at the end of a substitute
command caused the result of the substitution to be printed.  In the
current version the state of the `-n' switch is also checked.  Only
if output is disabled by default will the `p' flag have any effect.

This means that the example which you gave may be corrected by adding
the `-n' switch to the command line:

	sed -n 's/.*/&/p;d'

		Mark Lomas (tmal at cl.cam.ac.uk)



More information about the Comp.sources.bugs mailing list