Date: Mon, 1 Sep 1997 09:17:12 +0930 From: Greg Lehey <grog@lemis.com> To: gordon@iafrica.com Cc: Robert Chalmers <robert@chalmers.com.au>, freebsd-questions <freebsd-questions@FreeBSD.ORG> Subject: Re: Stripping ^M from llines? Message-ID: <19970901091712.45213@lemis.com> In-Reply-To: <Pine.BSF.3.95q.970831094346.4636G-100000@hole.iafrica.com>; from Gordon Greeff on Sun, Aug 31, 1997 at 09:48:33AM %2B0200 References: <34076F58.B5DBAC3F@chalmers.com.au> <Pine.BSF.3.95q.970831094346.4636G-100000@hole.iafrica.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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 <infile >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 <stdio.h> 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); } } ----------------------------------------------------------------------
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19970901091712.45213>