LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-08-2008, 11:25 AM   #1
horacioemilio
Member
 
Registered: Dec 2007
Posts: 61

Rep: Reputation: 15
How to get rid of the insane "^M"


Hi,

I got some files that I need to process and they contain some lines like this:

READ_CHARACTER^M_DONE

I checked and this "^M" thing makes me problem when I try to input this file to some program. If edit manually with vi and remove the "^M", then no problem.

But this file (and following) contains thousand of random appearances of this "^M". I thought about how to remove this. Perhaps sed -e "s/^M//g" could work, but I don't know how to use it.

Any suggestion ?

Thanks
 
Old 02-08-2008, 11:39 AM   #2
pvpnguyen
Member
 
Registered: Mar 2006
Posts: 38

Rep: Reputation: 15
Try dos2unix filename
 
Old 02-08-2008, 11:53 AM   #3
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
If you don't have dos2unix (I don't), you may want to consider using the tr utility (translate or delete characters) to replace the carriage returns with line feeds rather than simply deleting them (you can do that with tr too); from your example, it looks like you may want to translate rather than delete.

To do this, try tr [\r] [\n] < oldfile > newfile. Try it on a messy file and see if what you get is what you want. Then you can do something like this to clean up all of them:
Code:
#!/bin/sh
for file in *
do
     tr [\r] [\n] ${file} > tmpfile
     mv tmpfile ${file}
done
Hope this helps.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
I need to get rid of my old kbfx files to install new version - "access denied" Onewheelinweirdo Linux - Software 5 03-28-2007 08:04 AM
how to get rid of "warning : implicit declaration of function 'getpid' " ? diodio Linux - Newbie 6 02-01-2006 02:47 PM
cd mount mandriva 2005 "driving" me insane Skankpuss Linux - Hardware 2 05-28-2005 06:25 PM
When "function pointer" meets "template"... I can't get rid of this compiling er cyu021 Linux - Software 3 12-17-2004 07:52 PM
"Driving Me Insane" heartagram Linux - Software 2 09-16-2003 07:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration