On 9/23/05, Jay Savage <[EMAIL PROTECTED]> wrote:
>
> 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


Hello,

remove the last *pesky* character(^M)

I posted something like this ages ago, I imported an EndNote Library and it
was populated with ^M(s).

Xavier Noria suggested using:
perl -pi -we 's/\015/<replace_with>/g' filename
Which worked.

Hope that is of some use.

Dan.

Reply via email to