^M (how to delete it in a file)

^M (how to delete it in a file)

Post by Mario Stargar » Thu, 01 Mar 2001 05:53:28



        Use ascii mode when ftp-ing the files and it'll do the conversion for
you.
        Otherwise, use vi, sed or ex to change the files.
        In vi

:%s,^M$,,

        In sed

sed 's,^M$,,' filename > newfilename

        In ex you can change the files automatically without resorting to
having to create new files.

#!/bin/sh
for file in * ; do
        ex -s $file <<-_HERE_
        1,$s,^M$,,
        w
        q
        _HERE_
done

        ^M is literally <ctrl>V <ctrl>M.  The $ anchors the pattern match to
the end of the line.

        Cheers,
                Mario


> i have some files that were written with notepad or wordpad and when the
> file is transferred to an unix system and i use vi to read it, there is
> a ^M at the end of the line.

> basically, i need to delete the ^M character.  does anyone know how i
> can do this with going in and changing all the files manually?

> i assume that ^M is a character representation of a carriage return,
> right?

> thanks for any help

 
 
 

^M (how to delete it in a file)

Post by Ian P. Springe » Thu, 01 Mar 2001 15:01:13


tr -d ^M < file.txt > o
cp o file.txt
rm o

or write yourself a little shell script that does the above.


> is there a way to write the output to the same file name?

> if i have a file called file.txt and do the following:

> tr -d ^M < file.txt > file.txt

> the result is the file.txt is empty.  i want to keep the same file name
> with the new text.


> > On Solaris or Linux, you can use the dos2unix utility.  On HP-UX, use
dos2ux.
> > On other systems, you can use tr or sed (see the manpages).

> > -Ian



> > > i have some files that were written with notepad or wordpad and when the
> > > file is transferred to an unix system and i use vi to read it, there is
> > > a ^M at the end of the line.

> > > basically, i need to delete the ^M character.  does anyone know how i
> > > can do this with going in and changing all the files manually?

> > > i assume that ^M is a character representation of a carriage return,
> > > right?

> > > thanks for any help


 
 
 

^M (how to delete it in a file)

Post by George N. White II » Fri, 02 Mar 2001 01:02:20



> i have some files that were written with notepad or wordpad and when the
> file is transferred to an unix system and i use vi to read it, there is
> a ^M at the end of the line.

> basically, i need to delete the ^M character.  does anyone know how i
> can do this with going in and changing all the files manually?

> i assume that ^M is a character representation of a carriage return,
> right?

If you do this much you will also encounter encoding problems.  GNU
recode will convert DOS to unix newlines but can also change encodings.
You can overwrite the file in place or use it as a filter.

--

 
 
 

^M (how to delete it in a file)

Post by Danielle BOURRA » Fri, 02 Mar 2001 04:36:10


Hello,
Recently i have the same problem
On UNIX, you can take your file with the editor 'vi'
And then you can replace each caracter ^M with an another caracter or
sentence
You have to formulate :
:1,$s/^M/newcaracter/gp
Bye,
Danielle.



Quote:> i have some files that were written with notepad or wordpad and when the
> file is transferred to an unix system and i use vi to read it, there is
> a ^M at the end of the line.

> basically, i need to delete the ^M character.  does anyone know how i
> can do this with going in and changing all the files manually?

> i assume that ^M is a character representation of a carriage return,
> right?

> thanks for any help

 
 
 

^M (how to delete it in a file)

Post by laon » Fri, 16 Mar 2001 00:27:09


The new line character in Unix is ^J
If you transfer a text to a unix system from Dos/widows,
you can delete the ^M char in vi editor by the following command:

:%s/^M//
note that you should press Ctrl-V at first and then Ctrl-M when input "^M"
above;
or simply use:

:%s/.$//

use "asc" mode in ftp to transfer a text file like this can avoid the problem:

ftp> asc
200 Type set to A.
ftp> put xxx.txt
.......


> Hello,
> Recently i have the same problem
> On UNIX, you can take your file with the editor 'vi'
> And then you can replace each caracter ^M with an another caracter or
> sentence
> You have to formulate :
> :1,$s/^M/newcaracter/gp
> Bye,
> Danielle.



> > i have some files that were written with notepad or wordpad and when the
> > file is transferred to an unix system and i use vi to read it, there is
> > a ^M at the end of the line.

> > basically, i need to delete the ^M character.  does anyone know how i
> > can do this with going in and changing all the files manually?

> > i assume that ^M is a character representation of a carriage return,
> > right?

> > thanks for any help

 
 
 

^M (how to delete it in a file)

Post by Yue » Wed, 21 Mar 2001 12:58:10


There are two tools can help you,
dos2unix and unix2dos

>The new line character in Unix is ^J
>If you transfer a text to a unix system from Dos/widows,
>you can delete the ^M char in vi editor by the following command:

>:%s/^M//
>note that you should press Ctrl-V at first and then Ctrl-M when input "^M"
>above;
>or simply use:

>:%s/.$//

>use "asc" mode in ftp to transfer a text file like this can avoid the problem:

>ftp> asc
>200 Type set to A.
>ftp> put xxx.txt
>.......


>> Hello,
>> Recently i have the same problem
>> On UNIX, you can take your file with the editor 'vi'
>> And then you can replace each caracter ^M with an another caracter or
>> sentence
>> You have to formulate :
>> :1,$s/^M/newcaracter/gp
>> Bye,
>> Danielle.



>> > i have some files that were written with notepad or wordpad and when the
>> > file is transferred to an unix system and i use vi to read it, there is
>> > a ^M at the end of the line.

>> > basically, i need to delete the ^M character.  does anyone know how i
>> > can do this with going in and changing all the files manually?

>> > i assume that ^M is a character representation of a carriage return,
>> > right?

>> > thanks for any help

 
 
 

1. 'delete' command in ftp delete files in local hard disk ???

I write a batch file in Windows to download some files from an
UltraSPARC running Solaris in a LAN. The files will be deleted after
it was retrieved. Currently, I generate a ftp script file in the batch
file and pass it to ftp with 'ftp -ivn < myfile.ftp' in Windows.

The ftp script generated will be something like this:

open <ip_address>
user <username> <pass>
cd <source_path>
lcd <dest_path>
get myfile1
delete myfile1
get myfile2
delete myfile2
...
..
bye

Note that It is possible that the files are not available in the
UltraSPARC and it seems there is a bug in the ftp 'delete' command
(maybe in Windows environment).

The 'delete' command is supposed to delete the file in the REMOTE
environment, however, if the file does not exist in the UltraSPARC,
the 'delete' command will delete the file store in my LOCAL HARD DISK.

Is there anyway to prevent the 'delete' command to delete the files in
my local hard disk when it doesn't exist in thre UltraSPARC ?

\/\/yatt \/\/ong Home Page - http://www.asiaonline.net.hk/~tfwong/
Winona Ryder Forever H. P. - http://www.asiaonline.net.hk/~tfwong/winona/

Send a message with subject GET PGP KEY to get my PGP public key

2. No 32 bit support in M64 driver

3. It`s IMPORTANT!!!

4. a stable ICQ clone ?

5. Netscape plug-ins, helper files, Acrobat etc.

6. Network is unreachable errors

7. Please Help....it′s a very small thing!!!!.PLEASE

8. BSD 4.2 TALK FACILITY (request)

9. Help me !!!!!! I have no Idea it′s crucial

10. Compare file modification date using tcsh built-ins

11. It`s IMPORTANT!!!

12. recover deleted file in hp-ux ( vxfs file system)

13. Deleting Files Without Worrying about : Overriding Protection Of Your File