Jump to content

Recommended Posts

  • Moderators
Posted

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:

  Reveal hidden contents

 

Posted (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 by mikell
Posted

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

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
×
×
  • Create New...