Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Line ending issue DOS > Linux > Java

I'm having a bit of a trouble with a 160.000 lines file, this file was generated through an export from an xlsx file, it has a .txt extension but i'm afraid that it has been exported as DOS-like file, at the end of each line it has the DOS line break. I'm using a parser written in java, running on an Ubuntu environment, and i'm getting this when i run the parser (which i cannot edit because its part of a jar i cant access the source code), i get NumberFormatException where a number is expected, my line ends like this:

4449

But the parser sees it as

For input string: "4449&#xd;"<

Do you have a solution for this? again i cant access the parser myself, i will have to edit the file "on my Ubuntu machine" and remove those line ends.

like image 830
JBoy Avatar asked Jun 08 '26 16:06

JBoy


1 Answers

Try using the dos2unix command on that file. That should fix the line terminators.

> dos2unix winfile.txt unixfile.txt

Reference:
dos2unix man page

like image 167
Ravi K Thapliyal Avatar answered Jun 10 '26 05:06

Ravi K Thapliyal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!