1

The scenario where I am stuck is that I have a normal windows text file 'command.txt' which I am copying on remote(unix) server from my local machine(windows) using 'pscp' command from cmd.

The file contains some unix commands which are required to run on remote server. The copy is done successfully, but it is getting copied as dos file. That is why, when I am trying to run command.txt file from my local machine using 'plink' as:

plink -pw password user@host bash -m /location of command.txt on the server/command.txt 

It is unable to execute command.txt. So, I need some windows command or may be some pscp option to convert my file to unix text file before copying it on the remote server.

The solution I know is using dos2unix, but I don't want to use it.

2
  • 1
    The solution I know is using dos2unix but I dont want to use it. Why? Commented Mar 15, 2016 at 17:57
  • because it runs on Linux and as I am trying to do continuous deployment of which this task is a part, every task has to be executed on local machines i.e windows. Commented Mar 16, 2016 at 3:49

3 Answers 3

3

You seem to have problems with LF (line feed) characters in your text files produced on Windows box. If the file is not big you can use i.e. VBScript (it's on all Windows boxes, so no need to install additional tools) to remove the LF characters:

Dim objFSO Dim objOutput Set objFSO = CreateObject("Scripting.FileSystemObject") Set objOutput = objFSO.CreateTextFile("out.txt") arrData = Split(objFSO.OpenTextFile("in.txt").ReadAll, vbLf) For Each Item In arrData strData = strData & Replace(Item, vbLf, "") Next objOutput.WriteLine strData objOutput.Close 

Script presented above processes in.txt file into out.txt file, but can be easily extended to accept filenames from command line.

You can execute above script using cscript command:

cscript rem.vbs 
Sign up to request clarification or add additional context in comments.

Comments

1

You can run dos2unix on Windows too. Dos2unix is not limited to Linux. It runs on many platforms, including Windows. You only need to install it.

Comments

0

Thank you for the replies. The thing is that I have to perform this task only with the environment provided to me which is Windows and without downloading new features(I know its silly but I have no other option). One solution I found was to open the file in notepad++, go to the format tab and select 'convert to UNIX format'. It is working fine but as soon as I copy the file at some other location, its format again reverts back to windows format.

Is there any method to persist the changes in the format?

2 Comments

Can you give an example? I've never had this problem. I do things like - change the line ending with Notepad++, copy the file somewhere else, open up the file again with Notepad++ - and the UNIX format remains.
BTW, if you can use .NET (as in through PowerShell, look at any of: the answer here by@Krzysztof_Kielak ; SO Answer 2. If a batch file is OK, try JREPL.BAT as explained at SO Ans 3. You can also pick out what you need from github.com/guidoreina/dos2unix/tree/master if you're not able to just install from GitHub. (Sorry, no room for archived links. You can make this a new question ...)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.