I am having several files which I want to convert from Dos to Unix. Is there any API or method which will help me to do this?
unix2dos is a tool to convert line breaks in a text file from Unix format (Line feed) to DOS format (carriage return + Line feed) and vice versa. dos2unix command : converts a DOS text file to UNIX format. Unix2dos command : converts a Unix text file to DOS format.
Open Handbrake and click on Source. Then, select the file you want to convert; once it's loaded, click on the Enqueue button, and it will add the file to the queue. Click on Source again, select the next file, and add it to the queue. Repeat the process to add all the files that you want to convert (Figure 4).
There are linux tools that can do this (dos2unix
for example).
In Java it can be done with String.replaceAll()
.
DOS uses \r\n
for line termination, while UNIX uses a single \n
.
String unixText = windowsText.replaceAll("\r\n", "\n"); // DOS2UNIX
So no, no API exists. Yes, it is dead easy.
There is a utility/command in Linux/Unix called dos2unix
that will help you convert your files from dos to unix format. To install simply type in console(you may need root privileges)
yum install dos2unix
To do the conversion you have to use command dos2unix followed by filename. For example
[aniket@localhost ~]$ dos2unix sample.txt
dos2unix: converting file sample.txt to UNIX format ...
For all files in a directory you can simply use
dos2unix *
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With