we ran into carriage return and line feed issue during file transfer. The transfer was between different operating platform. The file was written on to FTP path from windows operating system and it read from Linux HP UX machine.
Issue: Additional CR (carriage return) character was added at the end every line
Cause: The mode of transfer was set to binary, actual mode that had to be used was ASCII mode.
This is due to the fact that new line character is handled differently in Windows and UNIX OS. On a Windows computer, pressing the “enter” key inserts two characters in an ASCII text document – a carriage return and a line feed. On UNIX systems, only a line feed is used. ASCII text formatted for use on UNIX systems does not display properly when viewed on a Windows system and vice verse.
So, what is the difference between ASCII and binary?
An ASCII file is a file represented internally using ASCII Codes. ASCII code is a 7-bit code stored in a byte. So in total there are 2^7 = 128 different ASCII codes. for every byte, one bit is wasted.
In binary 8 bits, that is 2^8 = 256 representations are possible.
Its not representation but OS defines what newline is:
DOS / Windows CR LF 0x0D 0x0A
Mac CR 0x0D
Unix LF 0x0A
Solution:
Use ASCII mode when different operating systems are involved else use binary mode to transfer binary files. Reading newline character as LF in UNIX and CRLF in windows is taken care automatically by OS. One shouldn’t worry about it.
-Manju