Updating docs

This commit is contained in:
Mike Farah
2025-03-03 15:12:22 +11:00
parent 19118c5552
commit 785ee2cabb
4 changed files with 68 additions and 4 deletions
+40
View File
@@ -109,6 +109,46 @@ cool:
- c: banana
```
## Sort a map
Sorting a map, by default this will sort by the values
Given a sample.yml file of:
```yaml
y: b
z: a
x: c
```
then
```bash
yq 'sort' sample.yml
```
will output
```yaml
z: a
y: b
x: c
```
## Sort a map by keys
Use sort_by to sort a map using a custom function
Given a sample.yml file of:
```yaml
Y: b
z: a
x: c
```
then
```bash
yq 'sort_by(key | downcase)' sample.yml
```
will output
```yaml
x: c
Y: b
z: a
```
## Sort is stable
Note the order of the elements in unchanged when equal in sorting.