From owner-freebsd-questions@FreeBSD.ORG Mon Jul 5 08:24:42 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6098C16A4CE for ; Mon, 5 Jul 2004 08:24:42 +0000 (GMT) Received: from smtp.infracaninophile.co.uk (happy-idiot-talk.infracaninophile.co.uk [81.2.69.218]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8C0AD43D1D for ; Mon, 5 Jul 2004 08:24:41 +0000 (GMT) (envelope-from m.seaman@infracaninophile.co.uk) Received: from happy-idiot-talk.infracaninophile.co.uk (localhost.infracaninophile.co.uk [IPv6:::1])i658Oax4067416 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 5 Jul 2004 09:24:36 +0100 (BST) (envelope-from matthew@happy-idiot-talk.infracaninophile.co.uk) Received: (from matthew@localhost)id i658OXvS067415; Mon, 5 Jul 2004 09:24:33 +0100 (BST) (envelope-from matthew) Date: Mon, 5 Jul 2004 09:24:33 +0100 From: Matthew Seaman To: Vulpes Velox Message-ID: <20040705082433.GB66477@happy-idiot-talk.infracaninophile.co.uk> Mail-Followup-To: Matthew Seaman , Vulpes Velox , Jon Drews , freebsd-questions@freebsd.org 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> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="61jdw2sOBCFtR2d/" Content-Disposition: inline In-Reply-To: <20040704202202.75528a32@vixen42.24-119-122-191.cpe.cableone.net> User-Agent: Mutt/1.5.6i X-Greylist: Message not sent from an IPv4 address, not delayed by milter-greylist-1.5.3 (smtp.infracaninophile.co.uk [0.0.0.0]); Mon, 05 Jul 2004 09:24:36 +0100 (BST) X-Virus-Scanned: clamd / ClamAV version devel-20040612, clamav-milter version 0.72a on smtp.infracaninophile.co.uk X-Virus-Status: Clean X-Spam-Status: No, hits=-4.8 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=2.63 X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on happy-idiot-talk.infracaninophile.co.uk cc: freebsd-questions@freebsd.org cc: Jon Drews Subject: Re: pattern replacement X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 Jul 2004 08:24:42 -0000 --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 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/--