TXT file - wrong view on Windows? [duplicate]

I just made a .txt file with my laptop (that runs Ubuntu 14.04), and when i open it with my Computer (runs Windows 10) it shows it like I wrote everything in one line

Maybe it's a dumb question, but I'm new to Ubuntu.

for example:

Ubuntu txt file

Windows same txt file


Solution 1:

Text files created on Windows machines have different line endings than files created on Linux.

  • Windows uses carriage return and line feed (\r\n)
  • Linux uses just line feed (\n).

There are a couple of methods to have it work on both ends:

  • When copying text files you need to use a tool that supports converting text files (like "winscp" on Windows).
  • With Windows Notepad++ you can replace \n by \r\n. Normal Notepad will not have this feature.
  • On Ubuntu you can use unix2dos testfile1.txt and dos2unix testfile2.txt to change line endings from one to the other. Also you can use the replace \n by \r\n on most editors or editors will have an option to switch between the too (like Serg in comments mentioned "nano").

Solution 2:

If your concern is to be able to open any arbitrary text file created on Linux in Windows, here are a couple of solutions.

First: Use Wordpad. Wordpad included in all recent versions of Windows is able to open Unix style text files. This is not always ideal, as it is not a text editor per se, but it can be a quick and easy way to open your Unix-style text files on Windows if you have not installed additional software.

Second: Install another text editor. If you control the box and use it regularly, this probably better. Most third party text editors will support both text styles. Two common, lightweight, and free options are Notepad2, which is a drop-in replacement for Notepad with a few extra features and Notepad++ which has a bit more features.