mirror of
https://github.com/mikefarah/yq.git
synced 2025-01-14 20:45:36 +00:00
Added custom sort map example
This commit is contained in:
parent
de053f6764
commit
2a3e78cb32
@ -107,6 +107,26 @@ KEY_a: 1
|
|||||||
KEY_b: 2
|
KEY_b: 2
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Custom sort map keys
|
||||||
|
Use to_entries to convert to an array of key/value pairs, sort the array using sort/sort_by/etc, and convert it back.
|
||||||
|
|
||||||
|
Given a sample.yml file of:
|
||||||
|
```yaml
|
||||||
|
a: 1
|
||||||
|
c: 3
|
||||||
|
b: 2
|
||||||
|
```
|
||||||
|
then
|
||||||
|
```bash
|
||||||
|
yq 'to_entries | sort_by(.key) | reverse | from_entries' sample.yml
|
||||||
|
```
|
||||||
|
will output
|
||||||
|
```yaml
|
||||||
|
c: 3
|
||||||
|
b: 2
|
||||||
|
a: 1
|
||||||
|
```
|
||||||
|
|
||||||
## Use with_entries to filter the map
|
## Use with_entries to filter the map
|
||||||
Given a sample.yml file of:
|
Given a sample.yml file of:
|
||||||
```yaml
|
```yaml
|
||||||
|
Loading…
Reference in New Issue
Block a user