Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert all EOL (dos->unix) of all files in a directory and sub-directories recursively without dos2unix

How do I convert all EOL (dos->unix) of all files in a directory and sub-directories recursively without dos2unix? (I do not have it and cannot install it.)

Is there a way to do it using tr -d '\r' and pipes? If so, how?

like image 421
user1316233 Avatar asked May 17 '12 02:05

user1316233


People also ask

How do I change the EOL for all files?

Just change "Search Mode" to "Extended", and you can work with EOL (\r\n in Windows or \n in Unix), tabs (\t), etc. You can also use the Find in Files tab of the dialog to do the replace across multiple files.

How do I convert EOL to Linux?

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.

Which Unix command will list all files and directories recursively?

ls -R : Use the ls command to get recursive directory listing on Linux.

How do I use dos2unix recursively?

If you want to automatically run dos2unix on hidden files and folders, you can use find or dos2unix ** **/. * The **/. * will expand only the hidden files and folders, including .


1 Answers

For all files in current directory you can do it with a Perl one-liner: perl -pi -e 's/\r\n/\n/g' * (stolen from here)

EDIT: And with a small modification you can do subdirectory recursion:

find | xargs perl -pi -e 's/\r\n/\n/g'
like image 163
smocking Avatar answered Sep 20 '22 04:09

smocking