Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Removing ^M characters from text documents

Posted on 2002-06-19
1
Medium Priority
?
159 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
1 Comment
 
LVL 85

Accepted Solution

by:
ozo earned 200 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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

886 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