Preserve new line characters when editing remote file from WinSCP

Viewed 566

As I understand, it is that if I create a file on my Solaris server I will automatically get LF ending line.

Setup: I am logged on to a Windows server remotely (with no internet as long as I am connected to it). On this Windows server I am using Winscp to log onto a solaris server.

Issue: When I create a text file on the Solaris server (using WinSCP), I can open it using Notepad++. When I open the file it always has CRLF as the newline character, I don't know why. Then I changed the CRLF character to LF by using 'find and replace' from '/r/n' to '/n'. When I find and replace I see that the newline character has been changed to 'LF'. However as soon as I save the file and reopen it we are back with 'CRLF'.

Could this be that notepadd++ is showing me false character maybe something to do with opening a Solaris file through WinSCP?

Or I should make the file using shell scripting (bash)?

Even if I make a file using shell script, how can I be sure that newline character in that file is LF not CRLF (is there a way of doing it on the terminal?), because right now I am using Notepad++ and it always shows CRLF as the newline character when I reopen the file.

Aim: What I want is simply create any text file with 'LF' as the newline character. I am using Solaris bash.

3 Answers

What winscp has done was that it opened an internal text editor for you to enter the text content. It saved to a temporary file locally on your Windows machine with the name you specified and finally transferred it in ascii mode to the Solaris.

When you downloaded it to your Windows, it was likely that it was downloaded in ascii mode too. As a result the change line characters were converted to Windows flavor CR+LF.

It looks ok. If you want to make sure of it, I would suggest you check the file content with an editor on Solaris such is vi. Winscp has a menu option Commands -> Open in PuTTY for you.

WinSCP by default does not convert the EOL sequence for editing files in an external editor, except if the editor is Windows built-in notepad.exe.

So you must have enabled the conversion in preferences yourself.

See Force text transfer mode for files edited in external editor option on Editor Preferences dialog:

enter image description here

With the option tuned off, you will get file opened in Notepad++ exactly as it is stored on the server.

There are some options. You could setup Notepad++ to create Unix style text files. Another option is to setup scp so that it transfer in text mode the text file. The third option, however it may be some inconvenient to run every time - dos2unix command does exactly what you need The fourth option is to use vi or some editor in the Unix terminal. I think there is no need to do scripting for that.

Related