Hello I am trying to find a reliable exe program to flip a text file from Unix to DOS and vice versa to use in an SSIS package. Any help is appreciated!!! :)
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.IO
Module Module1
Sub Main(args As String())
If args.Length <> 3 Then
Console.WriteLine("usage: UnixDosConvert <convertpattern> <infilename> <outfilename> ")
Console.WriteLine(" convertpattern can be UNIX2DOS or DOS2UNIX")
Return
End If
Dim byteCount As Long
Dim b As Byte
Dim fileInfo As New FileInfo(args(1))
Select Case args(0)
Case "UNIX2DOS"
Using inFs As New FileStream(args(1), FileMode.Open)
Using br As New BinaryReader(inFs)
Using outFs As New FileStream(args(2), FileMode.Create)
Using bw As New BinaryWriter(outFs)
For byteCount = 0 To fileInfo.Length - 1
b = br.ReadByte()
If b = 10 Then
bw.Write(CByte(13))
bw.Write(CByte(10))
Else
bw.Write(b)
End If
Next
End Using
End Using
End Using
End Using
Case "DOS2UNIX"
Using inFs As New FileStream(args(1), FileMode.Open)
Using br As New BinaryReader(inFs)
Using outFs As New FileStream(args(2), FileMode.Create)
Using bw As New BinaryWriter(outFs)
For byteCount = 0 To fileInfo.Length - 1
b = br.ReadByte()
If b = 13 Then
' do nothing '
ElseIf b = 10 Then
bw.Write(CByte(10))
Else
bw.Write(b)
End If
Next
End Using
End Using
End Using
End Using
End Select
End Sub
End Module
haydeez26
Member
5 Points
6 Posts
Dos to Unix or Unix to dos
Feb 23, 2012 09:17 PM|LINK
Hello I am trying to find a reliable exe program to flip a text file from Unix to DOS and vice versa to use in an SSIS package. Any help is appreciated!!! :)
Lannie
Contributor
3742 Points
730 Posts
Re: Dos to Unix or Unix to dos
Feb 24, 2012 03:02 AM|LINK
Put in a Console App and give it a test
Imports System.Collections.Generic Imports System.Linq Imports System.Text Imports System.IO Module Module1 Sub Main(args As String()) If args.Length <> 3 Then Console.WriteLine("usage: UnixDosConvert <convertpattern> <infilename> <outfilename> ") Console.WriteLine(" convertpattern can be UNIX2DOS or DOS2UNIX") Return End If Dim byteCount As Long Dim b As Byte Dim fileInfo As New FileInfo(args(1)) Select Case args(0) Case "UNIX2DOS" Using inFs As New FileStream(args(1), FileMode.Open) Using br As New BinaryReader(inFs) Using outFs As New FileStream(args(2), FileMode.Create) Using bw As New BinaryWriter(outFs) For byteCount = 0 To fileInfo.Length - 1 b = br.ReadByte() If b = 10 Then bw.Write(CByte(13)) bw.Write(CByte(10)) Else bw.Write(b) End If Next End Using End Using End Using End Using Case "DOS2UNIX" Using inFs As New FileStream(args(1), FileMode.Open) Using br As New BinaryReader(inFs) Using outFs As New FileStream(args(2), FileMode.Create) Using bw As New BinaryWriter(outFs) For byteCount = 0 To fileInfo.Length - 1 b = br.ReadByte() If b = 13 Then ' do nothing ' ElseIf b = 10 Then bw.Write(CByte(10)) Else bw.Write(b) End If Next End Using End Using End Using End Using End Select End Sub End Module