Line ending issue DOS > Linux > Java

混江龙づ霸主 提交于 2020-01-04 04:11:08

问题


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.


回答1:


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

> dos2unix winfile.txt unixfile.txt

Reference:
dos2unix man page




回答2:


The parser is finding &#xd;, which is a windows carriage return; however, it is unable to parse these characters. Go to the file and run a quick command tr -d '\15\32' < winfile.txt > unixfile.txt.

Reference: http://kb.iu.edu/data/acux.html



来源:https://stackoverflow.com/questions/17221720/line-ending-issue-dos-linux-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!