How to put CRLF to the specific text file


A third party XML generator creates a XML with only LF, so I have a problem to parse it by awk.
I’m thinking of the way that reading the file by TextInputStream and apply it with ReplaceLineEncodings method, and then run TextOutputStream to save it again.
However, it doesn’t look good.

Looking for a good idea to accomplish this requirement.
That is, is there any way to put CRLF to the specific text file?


are you selecting the correct EndofLineValue?

  • EndOfLine.Unix is LF [Unix and OSX]
  • EndofLine.MacIntosh is CR [OS9 not OSX]
  • EndofLine.WIndows if CRLF

I need to modify the statement I wrote. Sorry about that.

The generator creates a text file with only LF, and I couldn’t call the “ReplaceLineEndings” method to convert it.
I can only see the file on filesystem, and need to parse it.
With my text editor, I just see that LF at the end of line so have problem in parsing by awk.

Are you reading the XML into XOJO? if so, why not parse it into an ARRAY using SPLIT

No, my shell tries to read the text file(not XML) in the local file system. And, there awk.exe processes the file as an argument.

shell : awk -f test.awk theProblematicFile

awk '{printf "%s\\r\
", $0}' file

or something similar?

Yes, but “file” ends with only LF so my awk file has a problem to parse it.
I wanted to know how to put CRLF at the end of line of the “file”.

The below code doesn’t look good but it works.
I just read the file and apply ReplaceLineEndings to the file contents, then recreate the file.

Thanks for your help.

  Dim readString As String
  Dim readf As FolderItem = GetFolderItem(fileName)
  Dim f As FolderItem = New FolderItem(fileName,FolderItem.PathTypeAbsolute)
  Dim input As TextInputStream =
  readString = ReplaceLineEndings(input.ReadAll,EndOfLine.Windows)  //Adding LF (CRLF)
  If (f <> Nil) Then
      Dim t As TextOutputStream = TextOutputStream.Create(f)
      t = Nil
    Catch e As IOException
    End Try
  End If

[quote=231105:@Dave S]EndOfLine.Unix is LF [Unix and OSX]
EndofLine.MacIntosh is CR [OS9 not OSX]
EndofLine.WIndows if CRLF[/quote]

I have this small function within my templates:

[code] Function EOL() As String
// return a platform specific EndOfLine
#If TargetCarbon
Return Encodings.UTF8.Chr(13)
#ElseIf TargetCocoa
Return Encodings.UTF8.Chr(10)
#ElseIf TargetWin32
Return Encodings.UTF8.Chr(13) + Encodings.UTF8.Chr(10)
#ElseIf TargetLinux
Return Encodings.UTF8.Chr(10)
// raise new PlatformNotSupportedException
Return “”

	End Function[/code]