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?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
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
.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)To do the conversion you have to use command dos2unix followed by filename. For example
For all files in a directory you can simply use
The above line should remove all \r but for some reason it also removes the \n so I had to add it back when printing unixText to a file: unixText + "\n"
Most unix/linux distributions have utility named
unix2dos
anddos2unix
commands.EDIT: Just copy your file to unix machine and run
dos2unix *
.You can also find this utility for Windows and do the same.
Just an alternate way (than the one parasietje described) using dox2unix. Say you all dos files are in one folder