Jump to content

Recommended Posts

Posted (edited)

I'm trying to make more easy to identify lines of a txt.

Imagine a txt file with this content:

2021/01/01

2021/02/02

2022/02/02

I wanna see only those first two lines that are old.

Solution:


 
get-content "C:\school\result.txt" | where { [datetime]($_.split(','))[0] -lt (get-date).date.adddays(-30)}

 

Edited by alanbr00
Posted

? do you mean in AutoIt or in PowerShell?
Here a possible way in AutoIt

; #include <array.au3> ; if you want to use _array  functions

; read the file in a string
$string = FileRead("result.txt")

; clean the string from extra unwanted "WhiteSpaces"
$string = StringStripWS($string, 7) ; 7 ->  see help

; split dates into an array
$array = StringSplit($string, @CR, 2) ; 2 -> $STR_NOCOUNT

; Sort the array if needed ...
; _ArraySort($array)

ConsoleWrite($array[0] & @CRLF) ; print first date
ConsoleWrite($array[1] & @CRLF) ; print second date

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

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
  • Recently Browsing   0 members

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