alanbr00 Posted February 13, 2022 Posted February 13, 2022 (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 February 13, 2022 by alanbr00
Gianni Posted February 13, 2022 Posted February 13, 2022 ? 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 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
ad777 Posted February 13, 2022 Posted February 13, 2022 @alanbr00 how to use _DateDiff:https://www.autoitscript.com/autoit3/docs/libfunctions/_DateDiff.htm how to read first two line's:https://www.autoitscript.com/autoit3/docs/functions/FileReadLine.htm none
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