November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Categories

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

anooying ^M characters

When you sometimes copy a file from Windows to UNIX/Solaris or even Linux systems, you can find these anooying ^M characters everywhere. This is because, the file from Windows is in DOS (ASCII) format and needs to be converted to ISO format.

There are many ways to do this. Let’s start with the easy one look at each of them

1. Use dos2unix utility

Solaris pre-installs dos2unix utility into the system to do this job for you. As the name says, it converts the file from DOS format to UNIX format. To do this the syntax is

# dos2unix

for instance

# dos2unix test.txt test2.txt

Where the test.txt is the file you want the ^M characters removed and test2.txt is the file stripped of the ^M characters.

You may also overwrite the existing file by mentioning the source and destination files as same:

# dos2unix test.txt test.txt

2. Using VI

Open the file with “vi” editor and type the following:

:%s/^M//g

NOTE: To get the ^M in there, you should type CTRL+V+M
3. Using “tr” utility

“tr” utility is used to translate characters. Using with “-d” deletes a listed string.

# tr -d ‘\r’

Alternatively, use its octel representation as follows:

# tr -d ‘\015’

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>