Reverse sorting is another tricky one, but can be accomplished as well.
Sorting, reverse sorting, data summation by groups, all of these tend to be more of a Reporting need than a âprocess on the endpointâ type of need. In the reporting layer, you can use javascript and other tools that have inbuilt and easy methods for sorting, but since you asked, I am certainly one to rise to a challenge to show how it might be done at the BigFix agent level.
Could you please share your use case for this query?
It was not clear if you wanted to sort by the integer after the word test, or the part between the underscore and the dot. Either is doable with the techniques I will show below. I chose the slightly less wordy âtest#â prefix for this demo.
Starting with a simple filter to limit this to only the files starting with âtestâ
q: names of files whose (name of it as lowercase starts with "test") of folder "c:\test"
A: test1_20210123165009.txt
A: test2_20210124184449.txt
A: test3_20210125205107.txt
A: test4_20210126224733.txt
You probably noticed that Windows name sorts the files by default as part of our query.
Next up, build the reverse sorted portions as a string with separators, then use a reversing trick to reverse the entire string.
https://help.hcltechsw.com/bigfix/9.2/platform/Platform/Relevance/c_reversing_a_string.html
Q: concatenation "|" of preceding texts of firsts "_" of names of files whose (name of it as lowercase starts with "test") of folder "c:\test"
A: test1|test2|test3|test4
T: 9.571 ms
I: singular string
q: concatenation of characters (lengths of (following texts of (positions of it))) of concatenation "|" of preceding texts of firsts "_" of names of files whose (name of it as lowercase starts with "test") of folder "c:\test"
A: 4tset|3tset|2tset|1tset
T: 6.699 ms
I: singular string
Then we break it apart at the pipe and reverse each bit once again
q: (concatenation of characters (lengths of (following texts of (positions of it))) of it) of substrings separated by "|" of concatenation of characters (lengths of (following texts of (positions of it))) of concatenation "|" of preceding texts of firsts "_" of names of files whose (name of it as lowercase starts with "test") of folder "c:\test"
A: test4
A: test3
A: test2
A: test1
Now we have the exact sort we were searching for. We will use that in a minute.
Next we need to build a tuple to compare our sort with first and then stick that into a set (for efficiency)
q: (preceding text of first "_" of it, it) of names of files whose (name of it as lowercase starts with "test") of folder "c:\test"
A: test1, test1_20210123165009.txt
A: test2, test2_20210124184449.txt
A: test3, test3_20210125205107.txt
A: test4, test4_20210126224733.txt
T: 5.821 ms
I: plural ( substring, string )
q: set of (it as string) of (preceding text of first "_" of it, it) of names of files whose (name of it as lowercase starts with "test") of folder "c:\test"
E: This expression evaluates to an unrepresentable object of type "string set"
T: 2.883 ms
I: singular string set
Now we will put both parts together in one giant tuple, with the reverse sorted items as the first element and the set as the second one. This will allow us to retain the careful ordering we did in our prior step. If I was to Set the first part, it would undo our reverse sort, as sets dedupe and alpha sort when they are created.
q: (item 0 of it, elements of item 1 of it) of (((concatenation of characters (lengths of (following texts of (positions of it))) of it) of substrings separated by "|" of concatenation of characters (lengths of (following texts of (positions of it))) of concatenation "|" of preceding texts of firsts "_" of names of files whose (name of it as lowercase starts with "test") of folder "c:\test" ), (set of (it as string) of (preceding text of first "_" of it, it) of names of files whose (name of it as lowercase starts with "test") of folder "c:\test"))
A: test4, ( test1, test1_20210123165009.txt )
A: test4, ( test2, test2_20210124184449.txt )
A: test4, ( test3, test3_20210125205107.txt )
A: test4, ( test4, test4_20210126224733.txt )
A: test3, ( test1, test1_20210123165009.txt )
A: test3, ( test2, test2_20210124184449.txt )
A: test3, ( test3, test3_20210125205107.txt )
A: test3, ( test4, test4_20210126224733.txt )
A: test2, ( test1, test1_20210123165009.txt )
A: test2, ( test2, test2_20210124184449.txt )
A: test2, ( test3, test3_20210125205107.txt )
A: test2, ( test4, test4_20210126224733.txt )
A: test1, ( test1, test1_20210123165009.txt )
A: test1, ( test2, test2_20210124184449.txt )
A: test1, ( test3, test3_20210125205107.txt )
A: test1, ( test4, test4_20210126224733.txt )
By now you probably see we are headed towards the filter technique from the prior puzzler.
q: (item 0 of it, elements of item 1 of it) whose (tuple string item 0 of item 1 of it = item 0 of it) of (((concatenation of characters (lengths of (following texts of (positions of it))) of it) of substrings separated by "|" of concatenation of characters (lengths of (following texts of (positions of it))) of concatenation "|" of preceding texts of firsts "_" of names of files whose (name of it as lowercase starts with "test") of folder "c:\test" ), (set of (it as string) of (preceding text of first "_" of it, it) of names of files whose (name of it as lowercase starts with "test") of folder "c:\test"))
A: test4, ( test4, test4_20210126224733.txt )
A: test3, ( test3, test3_20210125205107.txt )
A: test2, ( test2, test2_20210124184449.txt )
A: test1, ( test1, test1_20210123165009.txt )
And finally we strip off the unneeded parts of the tuple where our sorting happened to get one possible solution.
Is this your card, @KeepLearning ?
q: tuple string items 1 of items 1 of (item 0 of it, elements of item 1 of it) whose (tuple string item 0 of item 1 of it = item 0 of it) of (((concatenation of characters (lengths of (following texts of (positions of it))) of it) of substrings separated by "|" of concatenation of characters (lengths of (following texts of (positions of it))) of concatenation "|" of preceding texts of firsts "_" of names of files whose (name of it as lowercase starts with "test") of folder "c:\test" ), (set of (it as string) of (preceding text of first "_" of it, it) of names of files whose (name of it as lowercase starts with "test") of folder "c:\test"))
A: test4_20210126224733.txt
A: test3_20210125205107.txt
A: test2_20210124184449.txt
A: test1_20210123165009.txt