Sed question

Matthew Seaman m.seaman at infracaninophile.co.uk
Thu Apr 15 16:58:41 BST 2004


--mxv5cy4qt+RJ9ypb
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Thu, Apr 15, 2004 at 04:43:40PM +0100, Mark Ovens wrote:
> Dave Tiger wrote:
>=20
> >Hi Sam,
> >
> > cat filename | sed -e "s/domain.com-edit\/1s/^L^Mtext to add/" filename
> >
>=20
> You can't write to the file you're reading from, try:
>=20
> mv filename filename.bu; cat filename.bu | sed
> 's/\(domain.com-edit\)$/\1\nThis is new text/' > filename
>=20
> All that is on one line of course.

If only.  Unfortunately FreeBSD sed(1) does not grok '\n' as a
character escape for new-line:

    % sed -e 's/\(domain.com-edit\)$/\1\nThis is new text/' <<E_O_T
    ? Some text
    ? Some more text
    ? substitution after domain.com-edit
    ? a bit more text
    ? the last text of all
    ? E_O_T
    Some text
    Some more text
    substitution after domain.com-editnThis is new text
    a bit more text
    the last text of all

That just inserts a letter 'n'...  This is the way to do it:

    % sed -e '/domain.com-edit$/a\\
    ? This is new text' <<E_O_T
    ? Some text
    ? Some more text
    ? substitution after domain.com-edit
    ? a bit more text
    ? the last text of all
    ? E_O_T
    Some text
    Some more text
    substitution after domain.com-edit
    This is new text
    a bit more text
    the last text of all

(Those ?'s are shell prompts, so don't type them in literally)

	Cheers,

	Matthew

--=20
Dr Matthew J Seaman MA, D.Phil.                       26 The Paddocks
                                                      Savill Way
PGP: http://www.infracaninophile.co.uk/pgpkey         Marlow
Tel: +44 1628 476614                                  Bucks., SL7 1TH UK

--mxv5cy4qt+RJ9ypb
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (FreeBSD)

iD8DBQFAfrExdtESqEQa7a0RAmMyAJ4qc7S3BRZyLpWOzcay9mQqssmqLgCeL04M
52VcX2Ek5OR4loFC/FWPzVU=
=/tHz
-----END PGP SIGNATURE-----

--mxv5cy4qt+RJ9ypb--




More information about the Ukfreebsd mailing list