Results 1 to 15 of 15
  1. #1
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Utility to translate LF to CRLF

    Can anyone point me at a simple utility which will take a LineFeed (LF)-delimited text file and produce a second text file with each LF translated to the usual DOS/Windows CarriageReturn/LineFeed (CRLF) pair?

    I haven't found anything obvious using Google...

    Thanks

    John
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

  2. #2
    Plutonium Lounger Leif's Avatar
    Join Date
    Dec 2000
    Location
    U.K.
    Posts
    14,010
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Utility to translate LF to CRLF

    Perhaps it could be done with Find and Replace using Word?

    Do you want it completely automated?

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Utility to translate LF to CRLF

    WordPad will do it - simply open the file and use Save or Save As.
    The old MS-DOS editor EDIT (still available in a command prompt) works too.

  4. #4
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Utility to translate LF to CRLF

    Thanks for those suggestions.

    I would prefer a utility because the source file is a configuration file for our Exchange antispam software, and I would prefer to minimise the possibility of accidentally changing the original by automatically creating a new file to play with!

    John
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Utility to translate LF to CRLF

    Until someone (Alan "Freeware" Miller probably) comes up with a utility, you could use the following macro. You can copy it into a module in any Office application (2002 or higher), for example Word. When run, the macro will prompt you to select a file, it will then create a file with "Copy of " prefixed to the name, with all LFs replaced with CRLFs.

    Note: if the file "Copy of ..." already exists, it will be overwritten without warning. Also, there is no check to see whether the selected file already has CRLF.

    Sub ConvertLF()
    Dim strFileIn As String, strFileOut As String
    Dim intPos As Integer
    Dim f As Integer, g As Integer
    Dim s As String * 1
    Dim i As Long
    With Application.FileDialog(msoFileDialogOpen)
    If .Show = True Then
    strFileIn = .SelectedItems(1)
    f = FreeFile
    Open strFileIn For Binary Access Read As #f Len = 1
    intPos = InStrRev(strFileIn, "")
    strFileOut = Left(strFileIn, intPos) & _
    "Copy of " & Mid(strFileIn, intPos + 1)
    g = FreeFile
    Open strFileOut For Binary Access Write As #g
    Do While Not EOF(f)
    Get #f, , s
    Put #g, , Replace(s, vbLf, vbCrLf)
    Loop
    Close #f
    Close #g
    End If
    End With
    End Sub

  6. #6
    5 Star Lounger
    Join Date
    Aug 2001
    Location
    Surrey, United Kingdom
    Posts
    1,001
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Utility to translate LF to CRLF

    Hi John

    Is this any good for what you want

    http://www.softmost.com/authors/brooks-int...ager/index.html

    Steve
    Cheers

    Steve

    Asking the questions everbody wants the answers too but feels too stupid to ask themselves :-)

  7. #7
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Utility to translate LF to CRLF

    How about Text Filter Utility?

    Alan

  8. #8
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Utility to translate LF to CRLF

    Alan

    That would probably be my preference -- but for the fact that it has to be compiled (as far as I can see...)!

    John
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

  9. #9
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Utility to translate LF to CRLF

    Sorry 'bout that. I'd think you'll find something similar at
    DOS Text Utility Programs - The Skeptic Tank
    or go to http://www.simtel.net and trawl through Desktop Publishing

  10. #10
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Phoenix, Arizona, USA
    Posts
    265
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Utility to translate LF to CRLF

    This will get you directly to the Desktop Publishing > Text Utilities http://www.simtel.net/category.php[id]298[SiteID]simtel.net
    <img src=/S/whisper.gif border=0 alt=whisper width=29 height=17>I just pasted the url between <!t><!/t> and <!t><!/t> and even though the url had a lot of % - everything appears to come out OK after previewing
    Ed
    "Somebody left the cork out of my lunch." - W. C. Fields

  11. #11
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Utility to translate LF to CRLF

    Is VBScript acceptable? See attached. (Sorry for the zip file, but vbs is not Lounge-safe.)

    As you can see, I've tried to handle a variety of potentially problematic situations (missing or invalid file name, output file exists), but I haven't run too many tests as the hour is late. <img src=/S/yawn.gif border=0 alt=yawn width=15 height=15>
    Attached Files Attached Files

  12. #12
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

  13. #13
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Utility to translate LF to CRLF

    toFrodos, isn't that Middle Earth-ware?

  14. #14
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Quedgeley, Gloucester, England
    Posts
    5,333
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Utility to translate LF to CRLF

    Alan

    I've ended up going with the TODOS.EXE utilty out of the ToFroDOS package you suggested. It is simple and handles the full serversharenamepathnamefilename UNC path that I didn't know I needed until I tried it this morning!

    Thanks to everyone for their efforts - much appreciated. (You won't be too surprised to know that I tried a simple BATch file, but this tends to come unstuck when text lines contain > and < and " characters...).

    John
    <font face="Script MT Bold"><font color=blue><big><big>John</big></big></font color=blue></font face=script>

    Ita, esto, quidcumque...

  15. #15
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Utility to translate LF to CRLF

    In a search for something else I came across this 2 year old thread on the VB/VBA board. For future reference by code-it-yourselfers: change CR to LF (vba 97).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •