Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert line endings [duplicate]

I have been using d2u to convert line endings. After installing Puppy Linux I noticed that it does not come with d2u, but dos2unix. Then I noticed that Ubuntu is missing both by default.

What is another way to convert line endings?

like image 729
Zombo Avatar asked May 27 '13 08:05

Zombo


People also ask

How do I change LF to CRLF in Notepad ++?

In Notepad++ go to the View > Show Symbol menu and select Show End of Line. Once you select View > Show Symbol > Show End of Line you can see the CR LF characters visually. You can then use the menu item Edit > EOL Conversion and select Unix (LF).

How do I change the EOL of a file?

To write your file in this way, while you have the file open, go to the Edit menu, select the "EOL Conversion" submenu, and from the options that come up select "UNIX/OSX Format". The next time you save the file, its line endings will, all going well, be saved with UNIX-style line endings.


1 Answers

Some options:

Using tr

tr -d '\15\32' < windows.txt > unix.txt 

OR

tr -d '\r' < windows.txt > unix.txt  

Using perl

perl -p -e 's/\r$//' < windows.txt > unix.txt 

Using sed

sed 's/^M$//' windows.txt > unix.txt 

OR

sed 's/\r$//' windows.txt > unix.txt 

To obtain ^M, you have to type CTRL-V and then CTRL-M.

like image 69
jaypal singh Avatar answered Sep 19 '22 11:09

jaypal singh