Jump to content

Read Second Line from last with text


Recommended Posts

  • Moderators

Vikramjeet,

Read the file into an array - extract the penultimate element.

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

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

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

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

×
×
  • Create New...