?
Solved

How do you strip ^M characters

Posted on 2003-03-06
10
Medium Priority
?
327 Views
Last Modified: 2013-12-06
Hello,

Are there better methods to strip out ^M characters other than DOS2UNIX?  DOS2UNIX seem to corrupt UTF-8 or double-byte characters.  Thanks.
0
Comment
Question by:bstevie
[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
10 Comments
 
LVL 18

Expert Comment

by:liddler
ID: 8078480
sed 's/^M//' file1 > file2
0
 
LVL 20

Accepted Solution

by:
Gns earned 200 total points
ID: 8078836
GNU recode will do a better job of converting text-files.
Get it from http://ftp.gnu.org/gnu/recode/
It's a bit overkill to just convert CR/LF to LF, but it can do that too:
recode /CR-LF.. file
and putting the CR back in there:
recode ../CR-LF file

It can do a lot more though:-).

-- Glenn
0
 
LVL 9

Expert Comment

by:HamdyHassan
ID: 8079717
as liddler  said, but make sure you click <CTRL>V<CTRL>M instead of type ^M

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 20

Expert Comment

by:Gns
ID: 8080148
Clarification: "... will do a better job..." is in reference to unix2dos/dos2unix, not the little sed snippet from liddler.

-- Glenn
0
 
LVL 8

Expert Comment

by:JIEXA
ID: 8082953
cat DOSFILE | tr -d '\015' > UNIXFILE

This filter is really shorter :-)
0
 
LVL 20

Expert Comment

by:Gns
ID: 8086989
I've been thinking (yeah, original:-), and I think the sed script and tr -d example run the same risc as unix2dos/dos2unix of corrupting double byte characters, since at least tr will remove a single byte (ie not treat the file as double byte character data).
I'm just theorizing (IOW I haven't tested on any such data), but it seems plausible:-).

recode should be well able to handle such data correctly though.

-- Glenn
0
 
LVL 1

Expert Comment

by:guerriero33t
ID: 8088406
I use the text editor. I open the file up with the text editor, select the ^M and then choose edit and replace all. For the replace with line you just leave it blank.

0
 

Expert Comment

by:acarlisle
ID: 8134680
You really only want to remove the CR characters at the end of a line, so you need something like this:

sed 's/\r$//' <filename>

(on my HP-UX system, this only works in a shell script.)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses
Course of the Month14 days, 3 hours left to enroll

801 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