pattern replacement
Matthew Seaman
m.seaman at infracaninophile.co.uk
Mon Jul 5 01:24:42 PDT 2004
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 at gmail.com> wrote:
> > Sed is useful for this. Here are some good tutorials on it:
> >
> > 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
>
> Cool, thanks... I working on something with a fix using head, grep,
> and cut :)
>
> 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
Some stuff
Some more stuff
This is the included text
A last chunk of stuff
Cheers,
Matthew
--
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20040705/2e8b5eef/attachment.bin
More information about the freebsd-questions
mailing list