Developer's Diary
Software development, with Terry Ebdon
|
I needed to add a sort step into a Windows command script running on a client system.
The input is a log file that had been pre-filtered by awk, and could be treated as space delimited. The required sort order was ascending by username (field 4) then timestamp (field 1). The safest way to do this is with a stable sort using field 4 as a single key. The stable sort preserves the logged order, within user, even if two log entries have the same timestamp.
The Windows utility seems very limited when compared to sort tools I've used in the past. Though it's interesting that this is the first time the command's simplicity has caused me a problem.
Point 1 isn't an issue here, but the key limitations, in points 2 and 3, were. I'd also be concerned that there's no option for a stable sort.
I could have worked around this by modifying the awk script, that generates the input file, to include a key field at the start of each line. I didn't consider that as I wanted to avoid changes to working code on a live system.
A POSIX compatible sort with a stable-sort extension, e.g. GNU sort, is significantly better, though it still has surprising limitations.
02-AUG-2020 👈 Top of page 👉 04-AUG-2020
© 2020 Terry Ebdon.
Find me coding on GitHub, networking on LinkedIn, answering questions on Stack Exchange and hanging out on twitter.