Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I write the following VB script in order to run commands from WIN XP on Linux machine and redirect the output command to out.txt file ( under C:\ )

My VB script I print the /etc/hosts file from Linux machine in to out.txt file

Script works fine but I have one problem:

/etc/hosts file was printed in out.txt file with one long line , in place of three lines

Example: (out.txt)
      localhost  MY_IP LOOP

In place to print the following host file in out.txt      localhost  MY_IP LOOP

MY VB script

Const TARGET_HOST = ""
const PATH =  "cat /etc/hosts" 
const LOGIN = "root"
const PASS = " dgdgd "
Const PLINKPATH="""C:\dir1\plink.exe"""
Set Sh = CreateObject("WScript.Shell")

CMD = " echo y | " &   PLINKPATH  & " -ssh -pw " & PASS & LOGIN & "@" & TARGET_HOST & " " & PATH 

Sh.Run "cmd /k" & CMD &  " > ""C:\out.txt""" , 1, True

Please advice what I need to fix in my VB script in order to print the correct hosts file ( line by line ) and not as one long line ?

share|improve this question
you really should troubleshoot things then you'd see that a file with a letter and a new line in linux, is smaller than a file with a latter and a new line in windows. In fact if in windows you do echo a>file1 then you see the file is 3 bytes, and you could ask the question -why-. And find out why. Windows using CRLF is extremely well known. if you ever read up about carriage return you'd probably learn windows uses it and linux just uses LF. i'd think one should run into that fact dozens of times. – barlop Sep 1 '13 at 21:52
up vote 0 down vote accepted

Linux systems use Line Feed for line breaks, whereas windows uses Carriage Return + Line Feed.

In your case, I would run PATH through sed, to replace the LF's with CRLF's

Const PATH = cat /etc/hosts | sed -e 's/$/\r/'

share|improve this answer
I haven't read his whole question, and it's shocking that a person(the questioner apparently) could know vbscript and where the hosts file is in linux, and not know about CRLF in windows and LF in linux. but anyhow, you write "replace the LF's with CRLF's" Then you write 's/$/\r/' what use would that replacement be - you're saying put CR at the end. that isn't used by any OS. it's either \r\n(CRLF) or it's \n(LF). never just \r(CR). and your sed replacement just puts a CR there. – barlop Sep 1 '13 at 21:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.