Solved

Removing ^M characters from text documents

Posted on 2002-06-19
1
152 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 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how do I grep for a specfic DNS record in a directory 3 44
Uploading Binary Data using Perl 5 89
Migrate OTRS to newest version. 1 326
How to get all the API from website? 11 86
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

776 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