Sign in to follow this  
Followers 0
dugz

show filtered part of textfile

3 posts in this topic

I'm a noob about coding some stuff,

but i had a problem with some autogenerated textfiles:

example, this is my text output:

4361275 01:32:30 11-07-09 4300119 DATA 8000 ? ">6"Z*·$!· *· *·)··$!@4·)"<(···;·.!aQ"z#`$z4`5'Melding7q·6`:a!;.BRANDSESTRAAT0=q·<` a"!+KAATSHEUVEL#q·"`&a$'&Prio:3)q·(`,a%--Tijd:01:02:28/q·.`2a*3(Status 15q·4`8a39%Terug;q::`?#·3

And i want to filter:

4361275 changes every new line

Melding is an static field stays in all the lines

BRANDSESTRAAT0 changes by every new line

KAATSHEUVEL changes by every new line

Prio:3 is an static field only number changes in 1, 2 or 3

Tijd: changes

Status changes but only the fist digit after Status need to be shown.

How can i filter this and how can ik show it in a screen?

Thnks for the help!

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Welkom to the forum, Dutch speaker. :)

Now, you want to read from text file.

You would need to read on function FileRead or FileReadLine.

http://www.autoitscript.com/autoit3/docs/functions/FileRead.htm

http://www.autoitscript.com/autoit3/docs/functions/FileReadLine.htm

Which one you use depends on your need.

Here is an example:

$StringFromTextFile = FileRead(@scriptdir & "\test.txt")
$aLines = StringSplit($StringFromTextFile, @CRLF, 1)    ;Split the string per line into array
For $i = 1 To $aLines[0]    ;$aLines[0] is the total line. So, it's from line 1 to last line.
    consolewrite($aLines[$i] & @CRLF)
    tooltip($aLines[$i])
    Sleep(500)
Next

Create a text file called test.txt in the script directory and write few lines there.

If you execute the script above, the script will show you each line.

If you want to read every 2 lines, you could add step in the For expression. So make it like: For $i = 1 To $aLines[0] step 2

And if you want you can show data using MsgBox function.

http://www.autoitscript.com/autoit3/docs/functions/MsgBox.htm

For the string filtering, you would need to read on StringInstr and other operations for String.

http://www.autoitscript.com/autoit3/docs/functions/StringInStr.htm

You can learn StringRegExp for more advanced usage.

I think that's all what you need to know to start your project.

Good luck.

Edited by MDCT

Share this post


Link to post
Share on other sites

I'm a noob about coding some stuff,

but i had a problem with some autogenerated textfiles:

example, this is my text output:

4361275 01:32:30 11-07-09 4300119 DATA 8000 ? ">6"Z*·$!· *· *·)··$!@4·)"<(···;·.!aQ"z#`$z4`5'Melding7q·6`:a!;.BRANDSESTRAAT0=q·<` a"!+KAATSHEUVEL#q·"`&a$'&Prio:3)q·(`,a%--Tijd:01:02:28/q·.`2a*3(Status 15q·4`8a39%Terug;q::`?#·3

And i want to filter:

4361275 changes every new line

Melding is an static field stays in all the lines

BRANDSESTRAAT0 changes by every new line

KAATSHEUVEL changes by every new line

Prio:3 is an static field only number changes in 1, 2 or 3

Tijd: changes

Status changes but only the fist digit after Status need to be shown.

How can i filter this and how can ik show it in a screen?

Thnks for the help!

Here is an example of my interpretation of what you require.

This may not work. If, for example, the ";." is not before the changeable "BRANDSESTRAAT0" and "=" is not after, then this regular expression pattern will not work. This also applies to other characters used to identify the location of the other required changeable data.

;
local $sREPattern = "^(\d+)\s(.*)(Melding)(.*);\.([A-Z0-9]+)=(.*)\+([A-Z]+)#(.*)(Prio:[1-3])(.*)-([A-Za-z]+):(.*)(Status \d)(.*)"

;Local $sStr = StringRegExpReplace(FileRead("Test.txt"), $sPattern, '\1 \3 \5 \7 \9 \11 \13')

local $sInStr = '4361276 01:32:30 11-07-09 4300119 DATA 8000 ? ">6"Z*·$!· *· *·)··$!@4·)"<(···;·.!aQ"z#`$z4`5''Melding7q·6`:a!;.BRANDSESTRAAT1=q·<` a"!+HAATSHEUVEL#q·"`&a$''&Prio:1)q·(`,a%--Bijd:01:02:28/q·.`2a*3(Status 25q·4`8a39%Terug;q::`?#·3'
Local $sStr = StringRegExpReplace($sInStr, $sREPattern, '\1 \3 \5 \7 \9 \11 \13')

MsgBox(0, "Result", $sStr)
;

A little explanation: The data collected from the search string which is accessed because of the RE, (Regular Expression), within each open & close brackets, (), can be back-referenced, \number. Each "(RE)" back-references is auto-numbered from left to right, \1 \2 \3 .... In this example the even numbered back-references are not replaced so they do not appear in the $sStr variable.

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0