Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 5 Jul 2004 09:24:33 +0100
From:      Matthew Seaman <m.seaman@infracaninophile.co.uk>
To:        Vulpes Velox <v.velox@vvelox.net>
Cc:        Jon Drews <jon.drews@gmail.com>
Subject:   Re: pattern replacement
Message-ID:  <20040705082433.GB66477@happy-idiot-talk.infracaninophile.co.uk>
In-Reply-To: <20040704202202.75528a32@vixen42.24-119-122-191.cpe.cableone.net>
References:  <20040704170807.2ea1ec75@vixen42.24-119-122-191.cpe.cableone.net> <8cb27cbf0407041551160a3b@mail.gmail.com> <20040704202202.75528a32@vixen42.24-119-122-191.cpe.cableone.net>

next in thread | previous in thread | raw e-mail | index | archive | help

--61jdw2sOBCFtR2d/
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sun, Jul 04, 2004 at 08:22:02PM -0500, Vulpes Velox wrote:
> On Sun, 4 Jul 2004 17:51:22 -0500
> Jon Drews <jon.drews@gmail.com> wrote:

> >  Sed is useful for this. Here are some good tutorials on it:
> >=20
> > Common threads: Sed by example:
> > http://www-106.ibm.com/developerworks/linux/library/l-sed1.html
> > http://www-106.ibm.com/developerworks/linux/library/l-sed2.html
> > http://www-106.ibm.com/developerworks/linux/library/l-sed3.html
>=20
> Cool, thanks... I working on something with a fix using head, grep,
> and cut :)
>=20
> Basically grep -n for #include or whatehet, pipe it into
> head -n 1 it, and then head -n (pervious number cut and minus one> the
> file, then >> the include into it, and the this is where I am stuck...
> I can't find a way to cat everything after a certian line number
> out :/

sed(1) is good for replacing one word with another one -- but the OP
was talking about implementing something more along the lines of what
#include does with the C pre-processor.  sed can certainly help to do
that, but it's not a complete solution.

There's in fact plenty of different ways to do this sort of thing.
Some more practical than others.  (I once, a long time ago, wrote a
website using server-side includes to implement a templating system,
using 'lynx -dump' to get apache to process the source files.)

Probably the official way to do this sort of thing is to use a macro
pre-processor.  cpp(1) has often been used, but it is pretty C
specific.  m4(1) is the general purpose solution but it's got a lot of
capabilities and is intimidating to the beginner:

    % cat foo
    This is the included text
    % cat bar
    Some stuff
    Some more stuff
    include(`foo')
    A last chunk of stuff
    % m4 < bar=20
    Some stuff
    Some more stuff
    This is the included text
   =20
    A last chunk of stuff

	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

--61jdw2sOBCFtR2d/
Content-Type: application/pgp-signature
Content-Disposition: inline

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

iD8DBQFA6RBBiD657aJF7eIRAjlhAJsHDEXk4J2sd4vHiTXSTpnofJEvOwCcCS1e
qSjMEI1ir4Orl+sEaQTnnn8=
=vlIe
-----END PGP SIGNATURE-----

--61jdw2sOBCFtR2d/--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040705082433.GB66477>