Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

How to delete ^M character using vi

Original Message
Name: Fabian
Date: September 20, 2001 at 01:48:58 Pacific
Subject: How to delete ^M character using vi
Comment:
Hi I am a beginner. I ftp a text file using binary and now when I modify the files I see a lot of ^M symbol at the end of every line. How do I get rid of this symbol quickly? I am about 200 lines per file to modify!! I want to use vi to make this modification

Report Offensive Message For Removal


Response Number 1
Name: ann
Date: September 20, 2001 at 10:20:31 Pacific
Subject: How to delete ^M character using vi
Reply: (edit)
Sometimes these characters are placed in a file during a DOS to UNIX conversion (these characters can only be viewed using an editor such as vi editor or using the cat –v command to view the file). To remove these characters, use the “tr –d” command to delete the control characters from the file (you may also use the :%s/.$// command in vi editor to delete ^M characters). After using “cat –v” to view the file, determine which control characters are present in the file. Refer to the ascii table (http://www.asciitable.com) to get the octal representation of the characters. The following is a brief list of Control characters octal representation:

Oct Dec Hex Name
000 0 0x00 NUL
001 1 0x01 SOH, Control-A
002 2 0x02 STX, Control-B
003 3 0x03 ETX, Control-C
004 4 0x04 EOT, Control-D
005 5 0x05 ENQ, Control-E
006 6 0x06 ACK, Control-F
007 7 0x07 BEL, Control-G
010 8 0x08 BS, backspace, Control-H
011 9 0x09 HT, tab, Control-I
012 10 0x0a LF, line feed, newline, Control-J
013 11 0x0b VT, Control-K
014 12 0x0c FF, form feed, NP, Control-L
015 13 0x0d CR, carriage return, Control-M
016 14 0x0e SO, Control-N
017 15 0x0f SI, Control-O
020 16 0x10 DLE, Control-P
021 17 0x11 DC1, XON, Control-Q
022 18 0x12 DC2, Control-R
023 19 0x13 DC3, XOFF, Control-S
024 20 0x14 DC4, Control-T
025 21 0x15 NAK, Control-U
026 22 0x16 SYN, Control-V
027 23 0x17 ETB, Control-W
030 24 0x18 CAN, Control-X
031 25 0x19 EM, Control-Y
032 26 0x1a SUB, Control-Z

For example, ^C is represented by “\003”, and ^M is represented by “\015”.

Use the following command to remove ^M characters:

tr -d "\015" newfile

Example: tr –d “\015” goodfile.txt



Report Offensive Follow Up For Removal

Response Number 2
Name: Leigh
Date: September 20, 2001 at 19:50:31 Pacific
Subject: How to delete ^M character using vi
Reply: (edit)
There is a much easier way.

In vi, do a :%s/^M//g

To get the ^M hold the control key, press V then M (Both while holding the control key) and the ^M will appear. This will find all occurances and replace them with nothing.

Hope this helps.
Leigh


Report Offensive Follow Up For Removal

Response Number 3
Name: David
Date: November 21, 2001 at 08:49:45 Pacific
Subject: How to delete ^M character using vi
Reply: (edit)
I Used :%s/^M/^M/g in Mac OS X in vi to
replace the ^M 's with carriage returns.
The first ^M is in capitals and the second
in lowercase (though it appears as
uppercase - wierd)

This worked.


Report Offensive Follow Up For Removal




Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: How to delete ^M character using vi

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




acer 312T BIOS problem

K7 Turbo possible max fsb?

Pc anywher problem

WinFLP & OE/Outlook2003

Computer resets after a few minutes


The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC