Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Feb 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Pearl or BAT? to do this

    i need to create a BAT file which does that following.

    -Take a Text file and replace data in it.
    (B_)(E_) = (BEGIN) (END)
    EX.
    F1 VA 5183 19.55150 81.345 89.24340"B_EP"
    F1 VA 5183 19.55150 81.345 89.24340"EP"
    F1 VA 5183 19.55150 81.345 89.24340"EP"
    F1 VA 5183 19.55150 81.345 89.24340"EP"
    F1 VA 5183 19.55150 81.345 89.24340"EP"
    F1 VA 5183 19.55150 81.345 89.24340"EP"
    F1 VA 5183 19.55150 81.345 89.24340"E_EP"
    **THIS IS THE ORIGINAL FILE FORMAT IN A *.TXT**

    I NEED IT TO LOOK LIKE THIS:
    BEG_EP
    F1 VA 5183 19.55150 81.345 89.24340"EP"
    F1 VA 5183 19.55150 81.345 89.24340"EP"
    F1 VA 5183 19.55150 81.345 89.24340"EP"
    F1 VA 5183 19.55150 81.345 89.24340"EP"
    F1 VA 5183 19.55150 81.345 89.24340"EP"
    F1 VA 5183 19.55150 81.345 89.24340"EP"
    F1 VA 5183 19.55150 81.345 89.24340"EP"
    END

    AND THE FOLLOWING: "C3_"

    F1 VA 5183 19.55150 81.345 89.24340"B_EP"
    F1 VA 5183 19.55150 81.345 89.24340"EP"
    F1 VA 5183 19.55150 81.345 89.24340"C3_EP"
    F1 VA 5183 19.55150 81.345 89.24340"EP"
    F1 VA 5183 19.55150 81.345 89.24340"EP"
    F1 VA 5183 19.55150 81.345 89.24340"EP"
    F1 VA 5183 19.55150 81.345 89.24340"E_EP"

    TO LOOK LIKE THIS
    BEGIN
    F1 VA 5183 19.55150 81.345 89.24340"EP"
    F1 VA 5183 19.55150 81.345 89.24340"EP"
    C3
    F1 VA 5183 19.55150 81.345 89.24340"EP"
    F1 VA 5183 19.55150 81.345 89.24340"EP"
    F1 VA 5183 19.55150 81.345 89.24340"EP"
    F1 VA 5183 19.55150 81.345 89.24340"EP"
    F1 VA 5183 19.55150 81.345 89.24340"EP"
    END

    Is this possible?
    I want to drop the ascii file into the bat file and then it spits it out with all the changes into another file or the same one.... But there is nothing really with fields... just takeing a B_ or E_ and renaming it to a BEG or END on a new line above or below of where that "B_" is located...

    I hope this is not hard...

    thanks for the help! really!

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Zwolle, The Netherlands
    Posts
    1,120
    Thanks
    2
    Thanked 31 Times in 31 Posts
    Is VBScript ok als well?
    Code:
    Dim objFileSys, objInputFile, objOutputFile, objArgs
    Dim strInputFileName, strOutputFileName, strInputLine, strOutputLine, strControl
    Dim intPosition, intPosition2
    
    'get filenames from commandline arguments
    Set oArgs = WScript.Arguments
    If oArgs.Count = 2 then
      strInputFileName = oArgs(0)
      strOutputFileName = oArgs(1)
    else
      msgbox("Please specify input- and outputfilename in command")
      Wscript.quit
    end if
    
    Set objFileSys = CreateObject("Scripting.FileSystemObject")
    Set objInputFile = objFileSys.OpenTextFile(strInputFileName,1,False)
    Set objOutputFile = objFileSys.OpenTextFile(strOutputFileName,2,True)
    
    Do
      strInputLine = objInputFile.ReadLine
      'check for presence of an underscore
      intPosition = InStr(strInputLine, "_")
      If intPosition > 0 Then
        'get position of doublequote
        intPosition2 = InStr(strInputLine, """")
        'get the characters between the doublequote and the underscore
        strControl = Mid(strInputLine, (intPosition2 + 1) , (intPosition - intPosition2 - 1) )
        'create the outputline, consisting of first part and last part concatenated, without the control part in it
        strOutputLine = Left(strInputLine, intPosition2) & Right(strInputLine, (Len(strInputLine) - intPosition))
        'write the neccesary lines in the oututfile
        Select Case strControl
          Case "B"
            objOutputFile.WriteLine "BEG_EP"
            objOutputFile.WriteLine strOutputLine
          Case "E"
            objOutputFile.WriteLine strOutputLine
            objOutputFile.WriteLine "END"
          Case Else
            objOutputFile.WriteLine strControl
            objOutputFile.WriteLine strOutputLine
        End Select
      Else
        'no underscore found, just write the line in outputfile
        objOutputFile.WriteLine strInputLine
      End If
    Loop Until objInputFile.AtEndOfStream
    
    ' clean up
    set objFileSys = Nothing
    objInputFile.Close
    set objInputFile = Nothing
    objOutputFile.Close
    set objOutputFile = Nothing
    set objArgs = Nothing
    save this code in a vbs-file

    call it like filename.vbs inputfile.txt outputfile.txt
    I am the luckiest man in the world

  • #3
    Mega-ultimate member
    Join Date
    Jun 2002
    Location
    Winona, MN - The land of 10,000 lakes
    Posts
    1,855
    Thanks
    1
    Thanked 45 Times in 42 Posts
    Technically, you could do this with just about any language you wanted to, but seeing as how PERL is the Practical Extraction and Reporting Language and was designed for fast, easy text manipulation, it may be a better tool (and faster, and more secure) than VB.


  •  

    Posting Permissions

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