ZTree.com  | ZEN  | About...  

 Index   Back

[OT] Batch file sorting help   [OT]

By: Ben Kent       
Date: Mar 21,2024 at 09:18
In Response to: [OT] Batch file sorting help (Paul Laufer)

> Can anyone figure out how to sort a fixed width file like this one
> by date using only batch commands on Windows 10/11?


This gets you mostly there, but as /+n sorts to end or line and weird US date format, the /+1 reverts the /+4, but it might be close enough for you

type %TEMP%\LookingForOST.TXT | sort /+4 /+1 /+7

To get correct sorting, use one of these

Use powershell, to parse and sort by the date
type %TEMP%\LookingForOST.TXT | powershell -c "$input | Sort-Object { [datetime]::ParseExact($_.substring(0, 19), 'MM/dd/yyyy hh:mm tt', $null)} "

Or use powershell to do the whole job
Get-ChildItem -LiteralPath 'C:\USERS' -Recurse -Force -Filter '*.ps1' | Select-Object LastWriteTime, Length, @{n='Owner'; e={(Get-Acl -LiteralPath $_.fullname).owner}}, fullname | Sort-Object LastWriteTime



Messages in this Thread

96,640 Postings in 12,231 Threads, 350 registered users, 67 users online (0 registered, 67 guests)
Index | Admin contact |   Forum Time: Apr 12, 2024 - 3:28 pm UTC  |  Hits:62,818,766  (14,297 Today )
RSS Feed