[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 338
  • Last Modified:

How do you strip ^M characters

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
bstevie
Asked:
bstevie
1 Solution
 
liddlerCommented:
sed 's/^M//' file1 > file2
0
 
GnsCommented:
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
 
HamdyHassanCommented:
as liddler  said, but make sure you click <CTRL>V<CTRL>M instead of type ^M

0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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

-- Glenn
0
 
JIEXACommented:
cat DOSFILE | tr -d '\015' > UNIXFILE

This filter is really shorter :-)
0
 
GnsCommented:
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
 
guerriero33tCommented:
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
 
acarlisleCommented:
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now