Jump to content

Recommended Posts

Posted

hey guys  I just cannot seem to figure out how to get this done.   I have a text file within that text file I have records.  Each record starts with 01|A.  

Example:

01|A|Data|Data

02|A|Data|Data

01|A|Data|Data <-- Start of new record

02|A|Data|Data

01|A|Data|Data   <--  Start of new record

02|A|Data|Data

02|A|Data|Data

02|A|Data|Data

01|A|Data|Data <-- Start of new record

02|A|Data|Data

So what I am trying to do is to get the file to look like this:

01|A|Data|Data 02|A|Data|Data

01|A|Data|Data 02|A|Data|Data

01|A|Data|Data 02|A|Data|Data 02|A|Data|Data 02|A|Data|Data

01|A|Data|Data 02|A|Data|Data

Were I am having the issue is when there is more the one(1) line that begins with 02|A|Data|Data.  I can only get the first 02|A|Data|Data to move to the same line with the 01|A|Data|Data

So I am just trying to get each record on a single line. 

Here is what I have tried

_FileReadToArray("C:\Temp\temp.txt", $aResults, $FRTA_NOCOUNT)

Local $aFinalResults[UBound($aResults)]

For $i = 0 to UBound($aResults) -1
    If StringLeft($aResults[$i], 4) = "01|A" Then
    $aFinalResults[$i] = $aResults[$i] & " " & $aResults[$i+1]
    EndIf
    Next
_ArrayDisplay($aFinalResults)
_FileWriteFromArray("C:\Temp\temp1.txt", $aFinalResults)

I have also tried with a While Wend loop but I am getting the same results.  Just the first 02|A|Data|Data line gets moved to the 01|A|Data|Data line.   

Can someone point me in the right direction to get this working correctly?

Posted
Local $sIn = FileRead("C:\Temp\temp.txt")
Local $sOut = StringRegExpReplace($sIn, "\R(?=02)", "")
ConsoleWrite($sOut & @LF)

 

  Reveal hidden contents

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

  • xcaliber13 changed the title to Loop / logic help [Solved]

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...