This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Security and the fly likes Remove ^M character in text file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » Security
Bookmark "Remove ^M character in text file" Watch "Remove ^M character in text file" New topic
Author

Remove ^M character in text file

Sivaraman Lakshmanan
Ranch Hand

Joined: Aug 02, 2003
Posts: 231
Hi All,
I sftp (secure FTP) some text files from unix box to another unix box using the JSCH API. When the same file is FTPed I don't see the ^M character but the SFTped file has a ^M characters at the end of each line of the file. I cannot use any utility to remove the ^M characters. Is there any settings that I can do in the Unix box to solve this or is there any settings in the JSCH API to solve this.

Any help on this is very much appreciated.


Regards,
Sivaraman.L
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41137
    
  45
FTP has a setting to transfer files in binary mode instead of ASCII mode; that should prevent any changes from happening.


Ping & DNS - my free Android networking tools app
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

Perhaps Ulf has it backwards? If you send it binary, it is send as is. If yo used it as text, it allows line conversions.

Many SFTP implementations don't have modes like ftp did. And since OP talks about using an API, what is supported depends on the API.

If you can't use something nice, like dos2unix, you can always just chop off the ^M at the end of lines after you use a readline() to get the string.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Remove ^M character in text file
 
Similar Threads
Invoking unix shell commands from java.
How to to recognize new line character?.
Reading logs from Unix server
Finding new line character or special characters in txt file ?
Different character sets on Unix/Windows? Whats happening?