locked
Dos to Unix or Unix to dos RRS feed

  • Question

  • User1458142556 posted

    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!!!  :)

    Thursday, February 23, 2012 5:17 PM

All replies

  • User269602965 posted

    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
    
    Thursday, February 23, 2012 11:02 PM