From owner-freebsd-questions Sun Aug 31 16:49:40 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.7/8.8.7) id QAA24307 for questions-outgoing; Sun, 31 Aug 1997 16:49:40 -0700 (PDT) Received: from nico.telstra.net (nico.telstra.net [139.130.204.16]) by hub.freebsd.org (8.8.7/8.8.7) with SMTP id QAA24302 for ; Sun, 31 Aug 1997 16:49:35 -0700 (PDT) Received: from freebie.lemis.com (gregl1.lnk.telstra.net [139.130.136.133]) by nico.telstra.net (8.6.10/8.6.10) with ESMTP id JAA02459; Mon, 1 Sep 1997 09:47:15 +1000 Received: (grog@localhost) by freebie.lemis.com (8.8.7/8.6.12) id JAA12320; Mon, 1 Sep 1997 09:17:14 +0930 (CST) Message-ID: <19970901091712.45213@lemis.com> Date: Mon, 1 Sep 1997 09:17:12 +0930 From: Greg Lehey To: gordon@iafrica.com Cc: Robert Chalmers , freebsd-questions Subject: Re: Stripping ^M from llines? References: <34076F58.B5DBAC3F@chalmers.com.au> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.81e In-Reply-To: ; from Gordon Greeff on Sun, Aug 31, 1997 at 09:48:33AM +0200 Organisation: LEMIS, PO Box 460, Echunga SA 5153, Australia Phone: +61-8-8388-8250 Fax: +61-8-8388-8250 Mobile: +61-41-739-7062 WWW-Home-Page: http://www.lemis.com/~grog Fight-Spam-Now: http://www.cauce.org Sender: owner-freebsd-questions@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk On Sun, Aug 31, 1997 at 09:48:33AM +0200, Gordon Greeff wrote: > On Sat, 30 Aug 1997, Robert Chalmers wrote: > >> Hi, >> Anyone got a handy program for stripping the ^M from text >> lines in fbsd? >> I currently use tr -d '\015', but this falls over text that >> has the : chararacter in it, complaining about it being a >> directory? > > There is a really easy way of doing it: > > load the file up in pico > hit enter once ( to add a line ) > save and quit > > fire it up in vi, and voila. Well, I suppose it's a matter of opinion whether that's an easy way to solve the problem. It requires a lot of keyboard input. Here's one which I would use. To compile, just: $ cc stripcr.c -o stripcr It's a filter: that is, you run it like this: $ stripcr outfile The reason for this isn't laziness: that way, you can pipe things into it. Greg stripcr.c: ---------------------------------------------------------------------- #define LINELENGTH 8192 /* max length of program line */ #include char inbuffer [LINELENGTH]; /* read in here */ char outbuffer [LINELENGTH]; /* write from here */ int main (int argc, char *argv []) { while (fgetsb (inbuffer, LINELENGTH, stdin)) { char *i = inbuffer; char *o = outbuffer; do { if (*i != '\r') /* not a CR */ *o++ = *i; /* copy it */ } while (*i++); fputs (outbuffer, stdout); } } ----------------------------------------------------------------------