Added ability to sort by multiple fields #1541

This commit is contained in:
Mike Farah
2023-02-11 04:46:39 +11:00
parent 5cb3c876fc
commit a1698b740a
3 changed files with 100 additions and 28 deletions
+22
View File
@@ -25,6 +25,28 @@ will output
- a: cat
```
## Sort by multiple fields
Given a sample.yml file of:
```yaml
- a: dog
- a: cat
b: banana
- a: cat
b: apple
```
then
```bash
yq 'sort_by(.a, .b)' sample.yml
```
will output
```yaml
- a: cat
b: apple
- a: cat
b: banana
- a: dog
```
## Sort descending by string field
Use sort with reverse to sort in descending order.