ftp the file

Dear

i ftp the text file from windows to aix , when i open that file every end of line contains ctrl^M character how can i avoid this junk character

Regards

Windows/DOS deals files in CR/LF format while unix just uses LF
mac i guess uses just CR.

You can use dos2unix (or any tool similar in aix) to convert
your windows file to unix fomat.

You may also try zipping file in windows and ftp'ing it
in "bin" mode.

Thanks

CR=Carriage return
LF=line feed

Dear Mah

thanks for your reply
i tried to by zip that file and ftp in bin mode , i encouter the same issue

Regards

The reason is that the end of a line is represented differently in DOS and UNIX. In DOS (and similar OSes) the end of a line is represented by two characters: CR (carriage return) and LF (line feed). his is much like the behaviour of a typewriter (the archetype of computer files), where at the end of a line, you wouls swing back the writing head to the beginning of the line (CR) and then feed some amount of paper to not overwrite the same line but write below it on the next (LF).

So, when you see some text in DOS (like in notepad or so) which looks like:

line 1
line2

in fact this would be the following succession of bytes:

line 1<CR><LF>line2<EOF>

Look at the file using a hex editor and you will see what i mean.

In UNIX the situation is differently: There is a special end-of-line-character, which denotes the end of a line. The same file under UNIX would look like (try it out by using the "od -ax" command)

line 1<EOL>line2<EOF>

Utilities like dos2unix do nothing else than convert the one format into the other by changing the <CR><LF>-sequences to <EOL>-characters and vice versa.

You don't even need these utilities when you transfer the file with ftp using the ASCII-mode instead of the binary mode. This is exactly the difference between the two. "Binary" means "do not exchange any CR/LF characters to <EOL> and vice versa" and "ASCII" means "do exchange..."

When you transfer the file in compressed format the ftp program will not recognize the ASCII format, because the compressed file is a binary file. Otherwise, when you transfer the text file in its natural form, many ftp-clients recognize it as text and switch to ASCII mode automatically, if yours does not you can simply switch yourself by issuing the "as" subcommand (and the "bi" subcommand to get back to binary mode again).

If you have transferred the file already and do not want to retransmit it you can easily change the file with sed:

sed 's/^M$//' file > file.changed

To enter the CTRL-M-char from the command line you can enter <CTRL>-V and then <CTRL>-M (hold down the <CTRL> key while pressing V or M respectively).

bakunin

Dear bakunin

could you please explore this command

sed 's/^M$//' file > file.changed

thanks for your quick reply

Regards

this is a simple sed-command substituting a "^M"-character followed by an end of line ("$") to "nothing", that is: deleting it. Note, that "^M" is NOT two characters, as in "caret-char, followed by an "M", but one character.

You cannot enter it directly by pressing down the <CTRL>-key and then press down <M>m as this would be translated to "end of line" by the shell. It would have the same effect as hitting the "<ENTER>"-key - open the next line of text. This is why you have to escape this character, which is done by first entering <CTRL>-V (hold down the CTRL-key, then press the <V>-key, then release the <CTRL>-key again) and only then enter the <CTRL>-M, which will now not be interpreted, but taken literally.

bakunin

Dear Bakunin

thanks for you explaination

Regards

you could use tr command for deleting ctrl+M characters .
use man tr you will get the solution.

thanks,
swatantra