Vikramjeet Posted October 14, 2018 Share Posted October 14, 2018 I need help with reading the second last line with text from a .log file. Can some provide a simple script...Thanks Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 14, 2018 Moderators Share Posted October 14, 2018 Vikramjeet, Read the file into an array - extract the penultimate element. M23 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...
Danp2 Posted October 14, 2018 Share Posted October 14, 2018 Some good discussion here -- Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
mikell Posted October 14, 2018 Share Posted October 14, 2018 (edited) My 2 cents, for the fun. This one doesn't exist in the topic mentioned above Msgbox(0,"", StringRegExpReplace(FileRead("test.txt"), '(?ms).*(^\N+$)\s*(?1)\s*\z', "$1") ) Edit For the fun, version 2 This one returns the n'th non-empty last line If n is greater than the number of non-empty lines, it returns the first non-empty line If the file is empty or blank, returns 0 Msgbox(0,"", _UmpteenthLastLine("test.txt", 3)) Func _UmpteenthLastLine($file, $n) Local $txt = FileRead($file) If not StringRegExp($txt, '\S') Then Return 0 Return StringRegExpReplace($txt, '(?ms).*?(^\N*\S\N*$)\s*(?:(?1)\s*){0,' & $n-1 & '}\z', "$1") EndFunc Edited October 14, 2018 by mikell Link to comment Share on other sites More sharing options...
Vikramjeet Posted October 15, 2018 Author Share Posted October 15, 2018 Thank you MVP. The Regular expression is perfect. Can you please help modify this script to read the 2nd last line and if the value in the second last line = "INVALID" then do something.....Thanks. Appreciate your help Link to comment Share on other sites More sharing options...
mikell Posted October 15, 2018 Share Posted October 15, 2018 5 hours ago, Vikramjeet said: Can you please help modify this script to read the 2nd last line .... That's what it does. 5 hours ago, Vikramjeet said: .... and if the value in the second last line = "INVALID" then do something This is a If/Then/EndIf condition including a basic string comparison . Look at the helpfile for Operators 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