Michael Peppler
Sybase Consulting
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
Sybase on Linux FAQ
Sybperl FAQ
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: "David Winters" <winters at snowstorm dot corp dot sgi dot com>
Subject: Re: Control Characters in a Pattern
Date: Feb 22 1996 6:16PM

|chitturi at 10:10am,2/22 scribed this stuff...
|How can I remove control characters in a string?
|I created a data file on my PC and ftpd the file to the UNIX system so
|that I can BCP into Sybase. When I use vi, the last character showns up as ^M.
|I want to delete this. It is a redundant character. I am writing a script
|to delete such control characters, not only at the end of the line but
|in the file. I know chop function only deletes at the end of the line but what
|about finding the control characters set in the middle of the line?
|Thank you in advance.
|Disclaimer = I question and speak for myself.
|__________________________End of Stuff________________________

	I've had a similar problem like that before also.  From what I
understand, DOS translates newlines (\n) into a linefeed (\l) and carriage
return (\r) whereas Unix thinks of newlines as linefeeds only?  Anybody know
for sure?

	Anyways my solution was to do a substitution for all those pesky ^M's
which seem to be carriage returns (\r).  The following is a bit of Perl code
that deletes those carriage returns.  I'm sure there's more eloquent ways to do
this but it works.


    open(INFILE, "<" . $infile) || die "Cannot open $infile";
    @lines = ;
    foreach (@lines) {
        s/\r//g;    # globally substitute all carriage returns with nothing

        /* do whatever you want to the lines here */


David Winters --
Magellan Database
Silicon Graphics, Inc.