Confusion with CRLF (wint) and LF (unix) as end of line seperators


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Confusion with CRLF (wint) and LF (unix) as end of line seperators
# 1  
Old 05-18-2011
Confusion with CRLF (wint) and LF (unix) as end of line seperators

I know that windows uses CRLF as a end of line character while Unix uses LF. But visually i could not see any difference in files while creating on either of plat forms.

CR (Carriage Return) means to bring cursor to beginning of line while LF (Line feed) means to bring cursor to next line without modifying its position.

Now when i hit enter on a file in windows, end of line is represented by CRLF, that's why i see the cursor at the beginning of next line. Now in unix also when i hit enter i see cursor on the beginning of next line but unix uses line feed only and not carriage return.

I am confused with this. Is there any way to visualize these? what additional benefit we are getting using CR in windows in addition if same result can be obtained using Line feed only.

Thanks
Sarbjit
# 2  
Old 05-18-2011
Use wordpad instead of notepad :

Wordpad will recognize if your file only has LF and will give a nice display ... notepad won't.

If CRLF formatted file, both notepad and wordpad will display it correctly.
# 3  
Old 05-18-2011
It is a historic design issue error in some early Operating systems, many of which precede Microsoft. Early printer-terminals were either real Teletypes or similar emulations of a typewriter.
Before proper printer drivers you used to print a file by copying it straight to the printer port down a serial cable. It needed the carriage-return character to print correctly.
Later printers had a dipswitch to optionally tell the printer to treat a linefeed as a carriage-return-line-feed.
The first PC which I came across with text files with carriage-return-line-feed as a text file record terminator was running Digital Research CP/M . The contemporary forerunners of modern unix did not have this issue.

In the modern world it still matters. You are best advised to use unix-format text files on unix and MSDOS format text files on Microsoft O/S because much software expects this.
This User Gave Thanks to methyl For This Post:
# 4  
Old 05-18-2011
Another way to look at it is as follows:

CR-LF are the actual bytes that would be sent over a serial port to most terminal devices. Microsoft, originally with DOS, chose to put those characters into a text file to mark end of line.

The Unix creators decided to instead use a single character to logically represent and end of line, call a New Line or NL, which somewhat coincidentally is the same byte code as a line-feed. It could actually have been anything as it need not have anything to do with the bytes actually sent to a terminal.

It's just a different philosophy. It might help if you think of the byte in Linux as a NL, not as a LF.
# 5  
Old 05-20-2011
It's really the program that is READing your file that interprets the LF or CR. Early when teletypes were system consoles, they needed more control, such as when someone logged in, they had to mask the password, so the system used CR, typed a string, then CR again typed another string, so it ended up a virtual black line. When Dot matrix was used, they knew which characters used each pin and could cover it a a couple of passes.

But it goes back to whose using it, most disk drives contain the number of bytes in the file, for example, you could have an executable with a byte(s) or CR or LF or CRLF. In which case it could be data or an instruction. In this case the OS would read data, length specified in the load module, from the disk, and load it to a specified location or let the OS move it to where it could run, then also in the data is an offset to execute, so the machine knows where to start the program. Writing in Assembly code, you can put data and code anywhere, then specify the starting point.

So in your instance it boils down to 'whose reading it'!

Hope this will help some....
# 6  
Old 05-20-2011
Notepad++ | 5.9
Also handles unix files, and has some other nice features.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Views How to replace a CRLF char from a variable length file in the middle of a string in UNIX?

My sample file is variable length, with out any field delimiters. It has min of 18 chars length and the 'CRLF' is potentially between 12-14 chars. How do I replace this with a space? I still want to keep end of record, but just want to remove these new lines chars in the middle of the data. ... (7 Replies)
Discussion started by: chandrath
7 Replies

2. UNIX for Beginners Questions & Answers

UNIX help adding data to end of a line with a variable

I am trying to add a date variable to the end of each line. This is what I have to start with cat ${DATAPATH}/Participate_Stream${STREAMDATE}.dryak1.csv | grep ^',' | awk '{print $0}' >> ${DATAPATH}/badparticipant.csv This is what I tried $DATE is a variable I have defined. cat... (3 Replies)
Discussion started by: req62861
3 Replies

3. Shell Programming and Scripting

Appending CRLF to end of record

I need to append |\r\n (a pipe character and CRLF) at end of each record in Unix to all records where they are not already present. So first check for the presence of |\r\n and if absent append it else do nothing (3 Replies)
Discussion started by: abhilashnair
3 Replies

4. Shell Programming and Scripting

Two field seperators with awk?

Im trying to brush up with my awk knowledge and update some old scripts to be a little more compact... What I would like to know how to do is the following: hostname,10.10.10.1 I have the above csv (with many more fields of course) how can I write a single line to pull field 2 from the... (7 Replies)
Discussion started by: trey85stang
7 Replies

5. Shell Programming and Scripting

Converting hex value 7C (for pipe) to CRLF in Unix

I am trying to convert a txt file that includes one long string of data. The lines are separated with hex value 7C (for pipe). I am trying to process this file using SQR (Peoplesoft) so I thought the easiest thing to do would be to replace the eol char with a CRLF in unix so I can just... (4 Replies)
Discussion started by: sfedak
4 Replies

6. Shell Programming and Scripting

Replacing end of line with " in a UNIX file

How should I replace End of line Character by ". i.e in a file - Name1,NO1 Name2,No2 Name3,No3 .... Should look like -- Name1,NO1" Name2,No2" Name3,No3" .... (2 Replies)
Discussion started by: The Observer
2 Replies

7. Programming

how to add CRLF support for CSV file generated in unix

Helo, my server side system is running on a redhat linux o.s. I have c program on the server which export list file into CSV format. now, I want that my program on server side is able to add support for CRLF(carriage return Line feed)into csv file format. so how do i write C program whcih... (3 Replies)
Discussion started by: amitpansuria
3 Replies

8. UNIX for Dummies Questions & Answers

How to convert ^M appearing at end of line to unix newline?

How to convert ^M appearing at end of line to unix newline? As I have tried with ^M in 'tr' it replaced ^ to a newline. Thanks in advance. (21 Replies)
Discussion started by: videsh77
21 Replies

9. Shell Programming and Scripting

windows file to unix :end line chararcter

hi , When i ftp a text file from Windows to unix enviornment and open the file in " vi editor" the end line charcrter of the windows file is seen as "cntrl+M" charcter in the Unix enviornment. Is there any command in unix , so that i dont see this "cntrl+M" chararcter in the... (9 Replies)
Discussion started by: dharmesht
9 Replies

10. UNIX for Advanced & Expert Users

Deleting UNIX End of Line Chachracter \000

Hi, I have this file which has some octal NULL characters (\000). I need to replace these characters with an ASCII NULL. I've tried using Perl, the UNIX tr command.. History of this I received a COBOL generated file, ran the od command to convert to a xxx byte per record file. Now,... (3 Replies)
Discussion started by: uchachra
3 Replies
Login or Register to Ask a Question