m.seaman at infracaninophile.co.uk
Thu Apr 15 16:29:52 BST 2004
Content-Type: text/plain; charset=us-ascii
On Thu, Apr 15, 2004 at 03:25:06PM +0100, Dave Tiger wrote:
> Sorry to be a bore but I cant get my head around sed and adding text to a
> file using it.
> I need to find the instance of "domain.com-edit" which is at the end of a
> line in a file and add a line of text under it.
> Sed -e "domain.com-edit" -e "s/text to add/g" filename=20
> Dose not work, I got the example of a website.
> Any help with this last piece of the puzzle is appreciated.
> Thank you in advance
As I remember, you wanted to search a file for any lines containing
'domain.com-edit' and add some text to the following line:
% sed -i~ -e '/domain.com-edit$/a\
Yes -- that is broken into two lines: it's a peculiarity of sed. You
have to insert a *literal* newline protected with a backslash. You
may need to double up the backslash at the end of the first line
depending on what shell you're using.
An alternative way of doing the job is:
% perl -pi~ -e 'm/domain.com-edit$/ && $_ .=3D "text-to-add\n";' filena=
Both of those commands save a copy of the original file as 'filename~'.=20
Dr Matthew J Seaman MA, D.Phil. 26 The Paddocks
PGP: http://www.infracaninophile.co.uk/pgpkey Marlow
Tel: +44 1628 476614 Bucks., SL7 1TH UK
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (FreeBSD)
-----END PGP SIGNATURE-----
More information about the Ukfreebsd