How to put CRLF to the specific text file

Hi,

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?

Thanks.

are you selecting the correct EndofLineValue?

xml=ReplaceLineEndings(xml,EndOfLine.Windows)
  • 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.

eg.
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 = TextInputStream.open(readf)
  readString = ReplaceLineEndings(input.ReadAll,EndOfLine.Windows)  //Adding LF (CRLF)
  
  If (f <> Nil) Then
    Try
      
      Dim t As TextOutputStream = TextOutputStream.Create(f)
      t.write(readString)
      
      t = Nil
      
    Catch e As IOException
    End Try
  Else
  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)
#Else
// raise new PlatformNotSupportedException
Return “”
#EndIf

	End Function[/code]