From owner-freebsd-questions Fri Aug 29 23:18:37 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.7/8.8.7) id XAA21472 for questions-outgoing; Fri, 29 Aug 1997 23:18:37 -0700 (PDT) Received: from mackay01.cqit.qld.edu.au (root@cqit.qld.edu.au [203.22.80.2]) by hub.freebsd.org (8.8.7/8.8.7) with ESMTP id XAA21465 for ; Fri, 29 Aug 1997 23:18:27 -0700 (PDT) Received: from carbon.chalmers.com.au (carbon.cqit.qld.edu.au [203.22.80.5]) by mackay01.cqit.qld.edu.au (8.7.3/8.6.9) with ESMTP id QAA20162 for ; Sat, 30 Aug 1997 16:13:28 +1000 (EST) Message-ID: <3407BA7B.3D5278DC@chalmers.com.au> Date: Sat, 30 Aug 1997 16:15:24 +1000 From: Robert Chalmers Reply-To: robert@chalmers.com.au Organization: chalmers.com.au X-Mailer: Mozilla 4.01 [en] (Win95; I) MIME-Version: 1.0 To: freebsd-questions Subject: Re: Stripping ^M from llines?[solved] X-Priority: 3 (Normal) References: <34076F58.B5DBAC3F@chalmers.com.au> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-questions@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk 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? > > cheers, > Bob Got sick of messing around and wrote a dos2unix thing in C. Works fine for what I want. Thanks for all the help folks. ========================== d2u.c ============================== #include #define MAXCHAR 128 main(int argc, char *argv[]) { int len; int foo; char string[128]; FILE *fileptr; /* check arguements */ if (argc != 2) error("Usage: d2u filename1 > filename2"); /* open file */ if ((fileptr = fopen(argv[1], "r")) == NULL) error("Cannot open file"); /* read material and display */ for (;;) { if (fgets(string, MAXCHAR, fileptr) != NULL) { len = strlen(string); for (foo = 0; foo <= len-1; foo++) { if (string[foo] != '\015') printf("%c", string[foo]); } } else exit(0); } } /* Process errors */ error(message) char *message; { printf("%s\n", message); exit(1); } -- http://www.chalmers.com.au Books-New & Secondhand Support Whirled Peas. Agents for CIBTC. Associate of Amazon.com, and Partner Program with iBS. Books about China, books from China. Sheng huo jiu shi dou zheng Business Links in Dalian, and Beijing. Building the China Trade