问题
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
"<
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 
, 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