Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!husc6!ogccse!littlei!omepd!merlyn From: merlyn@intelob.intel.com (Randal L. Schwartz @ Stonehenge) Newsgroups: comp.lang.c Subject: not the way ... (was Re: Want a way to strip comments from a) Message-ID: <4221@omepd.UUCP> Date: 16 Mar 89 22:37:19 GMT References: <7150@siemens.UUCP> <9900010@bradley> Sender: news@omepd.UUCP Reply-To: merlyn@intelob.intel.com (Randal L. Schwartz @ Stonehenge) Organization: Stonehenge; netaccess via BiiN, Hillsboro, Oregon, USA Lines: 33 In-reply-to: brian@bradley.UUCP In article <9900010@bradley>, brian@bradley writes: | > Does anyone have a sed or awk script which we | > can use to preprocess the C source and get rid of all the comments before | > sending it to the compiler? | | The following works in vi: :%s/\/\*.*\*\///g | | I don't know if it will work in sed, but it should... Nope. Just try it on the line: foo; bar; /* comment1 */ bletch; /* comment2 */ 'bletch;' disappears with the comments. The regexp that matches comments looks like (in egrep/lex notation): [/][*]([*]*[^*/])*[*]+[/] (I use [X] here instead of \X because I hate backslashes...). Sed and vi are not powerful enough to eat things like this in one regexp. Didn't we just go through this about nine months ago? :-) (And didn't I give the wrong answer at least twice? :-) :-) -- Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 on contract to BiiN (for now :-), Hillsboro, Oregon, USA. ARPA: <@intel-iwarp.arpa:merlyn@intelob> (fastest!) MX-Internet: UUCP: ...[!uunet]!tektronix!biin!merlyn Standard disclaimer: I *am* my employer! Cute quote: "Welcome to Oregon... home of the California Raisins!"