Script to open Unix .txt file and save as windows .txt file

Hello scripting experts - I was hoping someone could help me with a script that will save a text file that is generated on a Unix system to a Windows text file.  I'm missing the CRLF fields at the end of each line and saving as a Windows text file adds them in.  I'm doing this manually now with Textpad but it would be great to automate it.
LVL 1
First LastAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Seth SimmonsSr. Systems AdministratorCommented:
in linux you can use dos2unix and unix2dos to convert between the two systems
this comes in handy with those carriage returns

http://linuxcommand.org/man_pages/dos2unix1.html

http://www.linuxcommand.org/man_pages/unix2dos1.html
0
Gerwin Jansen, EE MVETopic Advisor Commented:
You're fast seth :)

unix2dos is the one you want, so:

unix2dos <your file>

Check file format with:

file <your file>

then you get either:

<your file> ASCII text, with CRLF line terminators

or

<your file> ASCII text
0
First LastAuthor Commented:
Ok, only problem is I'm on the windows side and don't have easy access to Linux (the file is generated by a 3rd party).  If I wanted to do this on Server 2008 what would be an easy option?  Thanks for the super-quick replies guys!
0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

Bill PrewCommented:
Or if you want to do it with a VBS script, here's a smal one for that.  Just save as a vbs file, and run it passing one, or two file names.  If you pass one, it will overwrite the file with the changes.  If you pass two file names, it will read from the first, and write to the second file (good for testing).

cscript yourname.vbs input.txt output.txt

' Define needed constants
Const ForReading = 1
Const ForWriting = 2
Const TriStateUseDefault = -2

' Get input file name from command line parm, if 2 parms entered
' use second as new output file, else rewrite to input file
If (WScript.Arguments.Count > 0) Then
  sInfile = WScript.Arguments(0)
Else
  WScript.Echo "No filename specified."
  WScript.Quit
End If
If (WScript.Arguments.Count > 1) Then
  sOutfile = WScript.Arguments(1)
Else
  sOutfile = sInfile
End If

' Create file system object
Set oFSO = CreateObject("Scripting.FileSystemObject")

' Read entire input file into a variable and close it
Set oInfile = oFSO.OpenTextFile(sInfile, ForReading, False, TriStateUseDefault)
sData = oInfile.ReadAll
oInfile.Close
Set oInfile = Nothing

sData = Replace(sData, vbLf, vbCrLf)

' Write file with any changes made
Set oOutfile = oFSO.OpenTextFile(sOutfile, ForWriting, True)
oOutfile.Write(sData)
oOutfile.Close
Set oOutfile = Nothing

' Cleanup and end
Set oFSO = Nothing
Wscript.Quit

Open in new window

~bp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
First LastAuthor Commented:
Just found unix2dos for Windows, it works perfectly and my script will very simple:

unix2dos filename.txt

Thanks guys!
0
Seth SimmonsSr. Systems AdministratorCommented:
you beat me to it...i was just about to post a link for the windows version of the tools on sourceforge.  glad it works for you
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.