On 9/23/05, Ryan Frantz <[EMAIL PROTECTED]> wrote: > > > > -----Original Message----- > > From: Ankur Gupta [mailto:[EMAIL PROTECTED] > > Sent: Friday, September 23, 2005 2:48 PM > > To: Dave Adams > > Cc: beginners perl > > Subject: Re: Looking for perl scripts to remove ^M > > > > On 9/23/2005 11:28 PM Dave Adams wrote: > > > > > Sometimes I get perl scripts that were developed on windows and then > > > brought over to UNIX and the scripts contain all the pesky > > > metacharacters of ^M and excessive blank lines. > > > > > > Does anyone have a simple script to clean these files up or > suggestions? > > > > If you are using vi/vim as your editor then this is the good way to > deal > > with it.. > > > > :%s/.$// > > This could also remove _any_ single characters just before the EOL that > aren't ^M. I know it's rare, but I've come across half-DOS, half-UNIX > text files like this where some EOLs had the DOS EOL char and some > didn't (I have no idea why other than someone was previously trying to > remove them...). > > > > > will remove the last *pesky* character(^M) from all lines.... > > > > But as Chris said, did you try anything so far... > > > > -- > > Ankur > >
Yeah, I've come across some weird encoding things, too. I've also run across situations where not all the returns were interpreted as EOL so 1) /\r$/ didn't match and 2) there were multiple ^M per line, so I needed /g anyway. I've become pretty fond of 's/[\r\f\n]+/\n/'. Note, though, that you'll lose double spacing that way. Probably hte best way to handle it is to open the input stream on DOS files :crlf, as in 'open(FH, "<:crlf", "dosfile")', and let perlio worry about it for you. HTH, -- jay -------------------------------------------------- This email and attachment(s): [ ] blogable; [ x ] ask first; [ ] private and confidential daggerquill [at] gmail [dot] com http://www.tuaw.com http://www.dpguru.com http://www.engatiki.org values of β will give rise to dom!