Solved

Removing ^M characters from text documents

Posted on 2002-06-19
1
157 Views
Last Modified: 2010-03-05
I'm a semi-newbie, but I have been working with perl for about a year now.  So bear with me.

I'm writing a script to take html files written in windows and remove the tags.  I've got everything under control except that I can't seem to get rid of some pesky ^M characters.  They're causing the text to lose the format I'm giving it, so they need to be removed.  I've tried to use some regular expressions:
     $text =~ s/^M//g; # Attempt 1

     $text =~ s/\^M//g; # Attempt 2

     $text =~ /.(.*)/g; # Attempt 3 (the ^M seems to be at the start of each line)
     $finished_text = $1;

Well, I've been trying things for a few days now, and am getting nowhere, so if someone could tell me what I'm doing wrong, it would be much appreciated.
0
Comment
Question by:tuxCharon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 84

Accepted Solution

by:
ozo earned 50 total points
ID: 7094538
$text =~ s/\cM//g;
or
$text =~ s/\r//g;
or
$text =~ s/\015//g;
or
$text =~ tr/\xd//d;
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question