Complete.Org: Mailing Lists: Archives: discussion: September 1998:
Re: [aclug-L] question
Home

Re: [aclug-L] question

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: aclug-L@xxxxxxxxxxxx
Subject: Re: [aclug-L] question
From: Steven Saner <ssaner@xxxxxxxxxxxxx>
Date: Thu, 10 Sep 1998 10:10:29 -0500
Reply-to: aclug-L@xxxxxxxxxxxx

On Thu, Sep 10, 1998 at 09:40:23AM -0500, Wesley Simon wrote:
> Does anyone know the syntax for a fancy tr command that I can put into a
> makefile so that it will strip the carriage return (^M) off each .c and
> .h file in a directory?  I used to have such a makefile, but I seem to
> have lost it during my last install.  If not, does anyone know a simple
> way of doing it?  I have about 30 files in a single directory.  I did
> several via command-line with "mv file.txt file.bak; tr -d '\r' <
> file.bak > file.txt", but that got a little tedious.  I'm doing some
> porting of some C programs and plan on doing this quite regularly, so I
> don't want to manually do it each time.  Any suggestions would be
> helpful.  I'm sure a 2 or 3 line perl script would do it too, but I'm
> not that familiar with perl at this point.  I would rather spend time
> working on the actual C code.

The background on this issue, for those that don't know, is the difference
in how DOS/Windows stores text files versus how Unix text files are
stored. In DOS/Windows, each line is terminated with both a linefeed
character and a carriage return. In Unix you have just a newline character
(which has the same ASCII value as the linefeed character). Therefore to
get the ^M's out of the file, you need to remove the carriage return from
each line. The way I do it is with the following perl script. It may not
be the best way, but it seems to work.

#!/usr/bin/perl

while(<STDIN>) {
   s/\x0d//;
   print;
}

I name this script crfilter
The syntax for using this is as follows:

cat filename | crfilter > filename

Another thing to note is when you ftp a text file from a DOS/Windows
system to a Unix system, specify the transfer type as ASCII instead of
Binary. That will usually do the conversion for you and prevent the
problem.

-- 
==================================================================
Steven Saner                            SouthWind Internet Access, Inc.
ssaner@xxxxxxxxxxxxx                    Technical Support
http://www2.southwind.net/~ssaner       support@xxxxxxxxxxxxx
                                        http://www.southwind.net
                                        263-7963 Wichita  (800)525-7963

---
This is the Air Capitol Linux Users Group discussion list.  If you
want to unsubscribe, send the word "unsubscribe" to
aclug-L-request@xxxxxxxxxxxx.  If you want to post to the list, send your
message to aclug-L@xxxxxxxxxxxx.



[Prev in Thread] Current Thread [Next in Thread]