Jump to content

Find value > 3600 on a txt and print the line


Recommended Posts

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
Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

  • Moderators

suprebosu,

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

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

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

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

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

#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".

Link to comment
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
 Share

  • Recently Browsing   0 members

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