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: c22309 at j1xsfs90 dot is dot nwa dot com (Mark Conty)
Subject: Re: Control Characters in a Pattern
Date: Feb 22 1996 4:26PM

Subbarao Chitturi writes:
> 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 anywhere
> 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?

If you were to do an "od -bc ..." of the UNIX file, you'd find that each
line is terminated not with simply a newline ("\n", 0x10), but with a
CR/newline combination ("\r\n", 0x1310).

What you can do to make it a proper UNIX file would be something like this
(assuming that each line is held in the "$_" variable):


... or if you want to strip out any '^M' characters ANYwhere, you could
just do:


... but if the CR were the only thing separating two lines, you'd end up
with an unintentionally joined line.  Thus, input of:

... would become:


That's why, IMHO, the first format is a better choice.

Good luck!
Mark D. Conty                       
Northwest Airlines                        
IS/Applications                   <><