superbosu Posted January 23, 2013 Share Posted January 23, 2013 (edited) 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 file.txt Edited January 23, 2013 by superbosu Link to comment Share on other sites More sharing options...
water Posted January 23, 2013 Share Posted January 23, 2013 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 2024-07-28 - Version 1.6.3.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 (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 More sharing options...
Moderators Melba23 Posted January 23, 2013 Moderators Share Posted January 23, 2013 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 superbosu 1 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
superbosu Posted January 23, 2013 Author Share Posted January 23, 2013 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 More sharing options...
Moderators Melba23 Posted January 23, 2013 Moderators Share Posted January 23, 2013 suprebosu,My most abject apologies - I was looking at the PID column! Just change $aRet[1]) to $aRet[3]). M23 superbosu 1 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
superbosu Posted January 23, 2013 Author Share Posted January 23, 2013 it works! tnx a lot MELBA23 Number 1! I realy love this forum! quick answers for everything you need. Link to comment Share on other sites More sharing options...
UEZ Posted January 23, 2013 Share Posted January 23, 2013 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 superbosu 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
superbosu Posted January 23, 2013 Author Share Posted January 23, 2013 Hi UEZ I tried your code with a file and it works too! tnx for the help Link to comment Share on other sites More sharing options...
junkew Posted January 23, 2013 Share Posted January 23, 2013 (edited) 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 January 23, 2013 by junkew FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
Malkey Posted January 23, 2013 Share Posted January 23, 2013 (edited) 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 January 24, 2013 by Malkey UEZ 1 Link to comment Share on other sites More sharing options...
UEZ Posted January 24, 2013 Share Posted January 24, 2013 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! 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 More sharing options...
JohnQSmith Posted January 24, 2013 Share Posted January 24, 2013 (edited) #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 January 24, 2013 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 More sharing options...
Malkey Posted January 24, 2013 Share Posted January 24, 2013 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now