Solved

Removing ^M characters from text documents

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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 …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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 video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now