2

As the title says it, Notepad doesn't show line breaks, specifically \n. But in Windows Explorer, in the preview window, it does show line breaks that are just \n (really Microsoft?). After doing some experimentation, it turns out notepad actually puts a \r\n for line breaks. This is annoying because the Mac TextEdit application just puts \n and as a user who uses both Mac and Windows simultaneously for programming purposes, this is very annoying. Is there anyway to make Notepad recognize just \n as a line break? I'm not sure why it doesn't because that's just an extra byte per line and in a CSV file that can really add up.

2 Answers2

4

Yes, Microsoft uses carriage return and line feed (both characters) for end of line but only one on Mac. In development, I use Adobe Dreamweaver which you can set to solve that. I develop on both Mac and Win platforms. I am unaware of making notepad do that however. You can try Wordpad, it handles it better than notepad though.

Jeff Clayton
  • 1,088
  • 8
  • 27
  • on my windows 7 ultimate, there's a wordpad.exe in a funny directory, that wouldn't run. So I copied it from XP and that ran – barlop Jul 18 '14 at 02:24
  • I have Win10 nowadays, you can add this to your path in your pc properties: C:\Program Files\Windows NT\Accessories if you want wordpad to work in the command prompt, or just launch it from the Cortana search prompt. – Jeff Clayton May 01 '18 at 19:05
  • Additionally, some people choose to use the third party program such as Notepad++ and set it to Unix mode which is the mode Mac is using. Wordpad does the trick and is bundled with Windows so no external program is actually needed. – Jeff Clayton May 01 '18 at 19:11
  • last time I checked, wordpad opens a file with unix line endings but saves it with windows line endings. – barlop May 02 '18 at 00:13
  • @barlop I have been editing unix files with wordpad for years due to multi-boot computers, and the re-saved file is readable in both Macs and PCs properly (Mac and PC being what the op requested) so it works as requested. – Jeff Clayton May 02 '18 at 12:40
  • The key here may well be the version of the Mac OS. OS X has been used for a very long time now, OS 9 and below did not handle both and not used by anyone now. So textedit can handle both on Mac -- Windows is the issue. – Jeff Clayton May 02 '18 at 12:47
  • Jeff, are you addressing me in that last comment? You said "Wordpad does the trick" I was addressing that. Sure wordpad is obviously a program in windows. That's what I was talking about. Wordpad. Notepad++ (also for windows), doesn't have the issue. – barlop May 02 '18 at 14:17
  • @barlop yes - the problem the op was having was that notepad was failing to work properly with the CR+LF differences, if you use wordpad on windows and textedit on mac there is no problem, but yes notepad++ is also a good option – Jeff Clayton May 02 '18 at 15:11
  • yes wordpad can open them though it's worth noting that when saving it it will save with crlfs. (which is often what you want in windows anyway. but one should know that it's doing that). – barlop May 02 '18 at 15:12
  • @barlop good info yes – Jeff Clayton May 02 '18 at 15:15
3

Mac is a Unix like operating system. Unix like operating systems do not use carriage return in outputting line breaks. So if you want your file show line breaks when opening it with notepad, you must first convert the file to a dos file.

So in Mac replace every occurrence of \n by \r\n

perl -pe 's/\r\n|\n|\r/\r\n/g' inputfile > outputfile

segfault
  • 81
  • 2
  • 10