Jump to content
Sign in to follow this  
superbosu

Find value > 3600 on a txt and print the line

Recommended Posts

superbosu

Hi all!

I have a file.txt with all info about process running and I want to print out only lines / rows that have a value bigger then 3600 under "Time"

So for example if I have the attacched file, I have to print the line or lines:

29 DIA 11440 Run yes no 1 5699 SAPDBKDF 150 U818BARONC

is this easy to do? I think I should use _FileReadToArray and then loop something but don't know what.

tnx for reply :bye:

file.txt

Edited by superbosu

Share this post


Link to post
Share on other sites
water

Looping though the array is a good idea!

Make sure that you translate the "number" derived from the text file to a real number (function Number). That's because a FileRead returns a string.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Melba23

superbosu,

This will write the lines with the "Run" value > 3600 to the SciTE console - up to you to get them printed: ;)

#include <File.au3>

Global $aLines
_FileReadToArray("file.txt", $aLines)

For $i = 6 To $aLines[0]
    $aRet = StringRegExp($aLines[$i], "(\d+)", 3)
    If Number($aRet[1]) > 3600 Then
        ConsoleWrite($aLines[$i] & @CRLF)
    EndIf
Next

Please ask if you have any questions. :)

M23

  • Like 1

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
superbosu

Hi Melba23 and tnx for the reply. :)

I tried your code with the file but the output was the same as the original file.txt without the top header lines:

Workprocess Table Wed Jan 23 16:03:53 2013

=================

No Type Pid Status Cause Start Rstr Err Time Program Cl User SemR SemL

------------------------------------------------------------------------------------------

right?

I think something is missing... any ideas?

Share this post


Link to post
Share on other sites
Melba23

suprebosu,

My most abject apologies - I was looking at the PID column! :>

Just change $aRet[1]) to $aRet[3]). :)

M23

  • Like 1

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
superbosu

it works! tnx a lot MELBA23

Number 1! :thumbsup:

I realy love this forum! quick answers for everything you need.

Share this post


Link to post
Share on other sites
UEZ

Here another similar way:

Global $aFilter = StringRegExp(FileRead(@ScriptDir & "\File.txt"), "\d+\h+\w+\h+\d+\h+\w+\h+\w+\h+\w+\h+\d+\h+\d+.*", 3)
If @error Then Exit
Global $i, $a, $sLines
For $i = 0 To UBound($aFilter) - 1
    $a = StringRegExp($aFilter[$i], "\d+\h+\w+\h+\d+\h+\w+\h+\w+\h+\w+\h+\d+\h+(\d+).*", 3)
    If @error Then ContinueLoop
    If $a[0] > 3600 Then $sLines &= $aFilter[$i] & @LF
Next
MsgBox(0, "Test", $sLines)

Br,

UEZ

  • Like 1

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
superbosu

Hi UEZ I tried your code with a file and it works too! tnx for the help

Share this post


Link to post
Share on other sites
junkew

Depending on the size of your file this could be faster

Local $file = FileOpen("file.txt", 0)
Local $fileData = FileRead($file)
FileClose($file)

$array=stringregexp($filedata, "\r\n(.{45})([3-9].{4})(.+\r\n)",4)
consolewrite("Length of file: " & stringlen($filedata) &@CRlf)
consolewrite("Analyzing " & UBound($array) & " lines" &@CRlf )

For $i = 0 To UBound($array) - 1
Local $match = $array[$i]
;~   For $j = 0 To UBound($match) - 1
;~  consolewrite( "Match " & $i & ',' & $j & ":" & $match[$j] & @CRlf)
;~   Next
if number($match[2])>3600 then
  consolewrite( "Match :" & $match[0] & @CRlf)
endif
Next
Edited by junkew

Share this post


Link to post
Share on other sites
Malkey

When testing, this example would return the lines with 4599, 5699, and 3601 in the "Time" column.

And this example would not return the lines with 2601, 3599, or 3600 in the "Time" column.

#include <Array.au3>

$aArray = StringRegExp(FileRead("file1.txt"), "((?:[^\s]+\h+){7}(?:[3-9][6-9][0-9][1-9]|[3-9][7-9][0-9][0-9]|[4-9][0-9][0-9][0-9])\h?[^\v]*\v*)", 3) ; )
ConsoleWrite(FileRead("file1.txt") & @LF)
_ArrayDisplay($aArray)

; Use if there are greater than 4 digit numbers expected.
$aArray = StringRegExp(FileRead("file1.txt"), "((?:[^\s]+\h+){7}(?:[3-9][6-9][0-9][1-9]|[3-9][7-9][0-9][0-9]|[4-9][0-9][0-9][0-9]|[1-9][0-9]{4,})\h?[^\v]*\v*)", 3)
_ArrayDisplay($aArray)

Edit: "|[3-9][7-9][0-9][0-9]" added to regular expression pattern because 3700, 3800, and 3900 were not being captured.

And added an adjusted JohnQSmith's example of post #12.

Edited by Malkey
  • Like 1

Share this post


Link to post
Share on other sites
UEZ

When testing, this example would return the lines with 4599, 5699, and 3601 in the "Time" column.

And this example would not return the lines with 2601, 3599, or 3600 in the "Time" column.

#include <Array.au3>

$aArray = StringRegExp(FileRead("file.txt"), "((?:[^\s]+\h+){7}(?:[3-9][6-9][0-9][1-9]|[4-9][0-9][0-9][0-9])\h?[^\v]*\v*)", 3) ; )

_ArrayDisplay($aArray)

Excellent solution Malkey! :thumbsup:

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
JohnQSmith

#include <Array.au3>

$aArray = StringRegExp(FileRead("file.txt"), "((?:[^\s]+\h+){7}(?:[3-9][6-9][0-9][1-9]|[4-9][0-9][0-9][0-9])\h?[^\v]*\v*)", 3) ; )

_ArrayDisplay($aArray)

What if some future value is greater than 4 digits? I'd recommend expanding it to...

$aArray = StringRegExp(FileRead("file.txt"), "((?:[^\s]+\h+){7}(?:[3-9][6-9][0-9][1-9]|[4-9][0-9][0-9][0-9]|[1-9][0-9]{4,})\h?[^\v]*\v*)", 3)
Edited by JohnQSmith

Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Share this post


Link to post
Share on other sites
Malkey

I realised that "[3-9][6-9][0-9][1-9]" in the regular expression pattern would not capture 3700, 3800, and 3900.

I have updated the example of post #10.

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  

×