Results 1 to 10 of 13
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 ...
- 02-08-2008 #1Just Joined!
- Join Date
- Dec 2007
- Posts
- 3
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
- 02-08-2008 #2
Use Backslash ( \ ) before ^ to override its default behavior :
Code:sed -e "s/\^M//g" <file_name>
It is amazing what you can accomplish if you do not care who gets the credit.
New Users: Read This First
- 02-08-2008 #3
There's a way to delete those guys without leaving vi:
Code::%s/<control-V><control-M>//g
--
Bill
Old age and treachery will overcome youth and skill.
- 02-08-2008 #4Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
- 02-08-2008 #5I think hefeweizen's example shows otherwise:It isn't necessary to use a backslash and the g option is redundant because every line has one ^M character at the end of the line
If there can be one ^M embedded in the middle of the line, there can be more than one.Code:READ_CHARACTER^M_DONE
--
Bill
Old age and treachery will overcome youth and skill.
- 02-08-2008 #6
Hi Friends !
I know a little about Scripting and try my hands sometimes.
Learning a lot from you all. Thanx...
It is amazing what you can accomplish if you do not care who gets the credit.
New Users: Read This First
- 02-08-2008 #7Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
- 02-08-2008 #8
- 02-09-2008 #9Linux Engineer
- Join Date
- Feb 2005
- Posts
- 1,044
The perl way:
Code:perl -pi -e 's/^M//' filename
- 02-09-2008 #10Of course, in that the ^M means "control vee, control em", as it did in the previous uses of it in this thread.The perl way:
Code:perl -pi -e 's/^M//' filename
The more conventional way in Perl is this, and in it you actually type all the characters as shown here. I've added back in the g, as noted in previous posts in this thread.
Code:perl -pi -e 's/\r//g' filename
--
Bill
Old age and treachery will overcome youth and skill.


Reply With Quote
