in reply to Cleaning Up Text Files

I too have some legacy Microsoft files that need to be cleaned up and I just haven't taken the time to sit down and do it yet. I was happy to see your simple code
perl -pi.bak -e 's/^M//g' *.xml
and I tried doing it as
perl -pi.bak -e 's/^M//g' testfile.html
It created the backup file, but did not remove the ^M's. Are there any other tricks to this?

Thanks.

Replies are listed 'Best First'.
Re: Re: Cleaning Up Text Files
by roik (Scribe) on Oct 25, 2002 at 12:41 UTC
    I think I have used \c instead of ^ in a regex in the past to do a similar thing. In your example:
    perl -pi.bak -e 's/\cM//g' testfile.html
      Cool! It worked. That little script made my day.

      I even used perl -pi.bak -e 's/\cM//g' *.html and my files were cleaned up in a couple seconds!

      Thanks for the help.
Re: Re: Cleaning Up Text Files
by cored (Scribe) on Oct 25, 2002 at 12:44 UTC
    Well that code works fine for me but you can try this one too and see what happend...
    perl -i.bak -pne 's/^M//g' file
    I only submit the -n option
      But if you're already using -p, there's no need for -n as well. perlrun says, "A -p overrides an -n switch." So adding -n actually does nothing at all.

      -- Mike

      --
      just,my${.02}