One thing to consider with the current method using linq is if there are lines that don't conform to your expected data in the text file. With that the following allows for issues e.g. line does not have expected number of columns or the line is blank.
There is more code than a one line lambda or linq statement but as indicated above to allow for use of assertion.
Imports Microsoft.VisualBasic.FileIO
Public Class Form2
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim readFile As String =
IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Textfile1.txt")
Dim writeFile As String =
IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Textfile2.txt")
Dim Lines As New List(Of Line)
Using reader As New TextFieldParser(readFile)
reader.TextFieldType = FieldType.Delimited
reader.Delimiters = New String() {","c}
Dim currentRow As String()
While Not reader.EndOfData
'
' Feel free to discard the try/catch if so be it
'
Try
currentRow = reader.ReadFields()
Lines.Add(New Line(currentRow))
Catch ex As MalformedLineException
' decide how to handle
End Try
End While
End Using
IO.File.WriteAllLines(writeFile,
Lines.OrderBy(Function(item) item.Column0) _
.Select(Function(item) item.ItemArray).ToArray)
End Sub
End Class
''' <summary>
''' Used to create a line item that will
''' be inserted into a List(Of Line) in the caller
''' reading a text file.
''' </summary>
''' <remarks>
''' Gave generic names to properties, we could do an
''' an anonymous type inside of Lambda or Linq and done
''' away with the class but felt this is simply another
''' option
''' </remarks>
Public Class Line
Public Property Column0 As String
Public Property Column1 As String
Public Property Column2 As String
Public Property Column3 As String
Public Property Column4 As String
Public Property Column5 As String
Public Sub New(ByVal sender As String())
If sender.Length = 6 Then
Column0 = sender(0)
Column1 = sender(1)
Column2 = sender(2)
Column3 = sender(3)
Column4 = sender(4)
If sender(5) = "270" Then
Column5 = "-90"
Else
Column5 = "270"
End If
Else
' decide how to handle incorrect columns in a line
End If
End Sub
Public Function ItemArray() As String
Return String.Format("{0},{1},{2},{3},{4},{5}",
Column0, Column1, Column2, Column3, Column4, Column5)
End Function
End Class