Operation request: Unique/Sort lines based on part of it
- Dominant language
- JavaScript
- Stars
- 35.8k
- Forks
- 4.1k
- Avg merge
- 2d 26m
- Merged PRs (30d)
- 33
Description
## Summary
- Ability to sort input lines based on regex, or even better if we can sort the whole input lines based on `Subsection`
- Ability to get unique lines based on part of a line.
### I want to get the most recent backup file of each database:
### Example Input
> ABC_backup_2024_04_19_030015_4199663.bak
> ABC_backup_2024_04_26_031328_7771579.bak
> ABC_backup_2024_05_10_030015_4434976.bak
> ABC_backup_2024_05_03_030022_5120774.bak
> KQMO_backup_2024_04_19_030014_8992595.bak
> KQMO_backup_2024_04_26_031328_2733774.bak
> KQMO_backup_2024_05_03_030021_8090927.bak
> KQMO_backup_2024_05_10_030014_9279748.bak
> QWERTY_backup_2024_04_19_030015_5155445.bak
> QWERTY_backup_2024_04_26_031328_8747284.bak
> QWERTY_backup_2024_05_10_030015_5372286.bak
> QWERTY_backup_2024_05_03_030022_6214310.bak
### Example Output
> ABC_backup_2024_05_10_030015_4434976.bak
> KQMO_backup_2024_05_10_030014_9279748.bak
> QWERTY_backup_2024_05_10_030015_5372286.bak
For me to do that in the current version of CyberChef, I had to do the following steps:
1. swap the DB name with the date
2. convert date to timestamp
3. sort numeric
4. convert back timestamp to date
5. swap back date with the name
6. using regex Extract unique lines (last occur of each name [the lines are sorted based on date already])
Here is my attempt: [Recipe](https://gchq.github.io/CyberChef/#recipe=Comment('Swap%20Name%20with%20the%20date%20in%20order%20to%20sort%20based%20on%20the%20date.')Find_/_Replace(%7B'option':'Regex','string':'(.%2B?)_backup_(%5C%5Cd%7B4%7D_%5C%5Cd%7B2%7D_%5C%5Cd%7B2%7D)'%7D,'$2_backup_$1',true,false,true,false)Comment('Convert%20date%20to%20timestamp%20(int),%20and%20sort%20numeric')Subsection('(%5C%5Cd%7B4%7D_%5C%5Cd%7B2%7D_%5C%5Cd%7B2%7D)_.%2B',true,true,false)Translate_DateTime_Format('International%20date%20and%20time','YYYY_MM_DD','UTC','x','UTC')Merge(true)Sort('Line%20feed',false,'Numeric')Comment('convert%20timestamps%20back%20to%20original%20date%20format')Subsection('(%5C%5Cd%2B)_.%2B',true,true,false)Translate_DateTime_Format('UNIX%20timestamp%20offset%20(milliseconds)','x','UTC','YYYY_MM_DD','UTC')Merge(true)Comment('swap%20back%20date%20with%20the%20name.')Find_/_Replace(%7B'option':'Regex','string':'(%5C%5Cd%7B4%7D_%5C%5Cd%7B2%7D_%5C%5Cd%7B2%7D)_backup_(.%2B?)_'%7D,'$2_backup_$1_',true,false,true,false)Comment('Extract%20unique%20lines%20(last%20occur%20of%20each%20name)')Regular_expression('User%20defined','%5E(.%2B?)_backup.%2B(?!%5B%5C%5Cw%5C%5CW%5D*%5C%5C1_backup)',true,true,false,false,false,false,'List%20matches')Sort('Line%20feed',false,'Alphabetical%20(case%20sensitive)')&input=QUJDX2JhY2t1cF8yMDI0XzA0XzE5XzAzMDAxNV80MTk5NjYzLmJhawpBQkNfYmFja3VwXzIwMjRfMDRfMjZfMDMxMzI4Xzc3NzE1NzkuYmFrCkFCQ19iYWNrdXBfMjAyNF8wNV8xMF8wMzAwMTVfNDQzNDk3Ni5iYWsKQUJDX2JhY2t1cF8yMDI0XzA1XzAzXzAzMDAyMl81MTIwNzc0LmJhawpLUU1PX2JhY2t1cF8yMDI0XzA0XzE5XzAzMDAxNF84OTkyNTk1LmJhawpLUU1PX2JhY2t1cF8yMDI0XzA0XzI2XzAzMTMyOF8yNzMzNzc0LmJhawpLUU1PX2JhY2t1cF8yMDI0XzA1XzAzXzAzMDAyMV84MDkwOTI3LmJhawpLUU1PX2JhY2t1cF8yMDI0XzA1XzEwXzAzMDAxNF85Mjc5NzQ4LmJhawpRV0VSVFlfYmFja3VwXzIwMjRfMDRfMTlfMDMwMDE1XzUxNTU0NDUuYmFrClFXRVJUWV9iYWNrdXBfMjAyNF8wNF8yNl8wMzEzMjhfODc0NzI4NC5iYWsKUVdFUlRZX2JhY2t1cF8yMDI0XzA1XzEwXzAzMDAxNV81MzcyMjg2LmJhawpRV0VSVFlfYmFja3VwXzIwMjRfMDVfMDNfMDMwMDIyXzYyMTQzMTAuYmFr)
Contributor guide
Research direction
Start by examining the existing Subsection, Sort, and Regular expression operations referenced in the recipe, including how they handle regex-based selection and line ordering. Define the requested behavior for sorting whole lines by a captured part and retaining one line per matching part; done should reproduce the example output without the multi-step workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- data
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100