mirror of
https://github.com/mikefarah/yq.git
synced 2026-09-01 14:14:52 +08:00
Simplified yq usage
This commit is contained in:
@@ -5,11 +5,13 @@ The Sort Keys operator sorts maps by their keys (based on their string value). T
|
||||
Sort is particularly useful for diffing two different yaml documents:
|
||||
|
||||
```bash
|
||||
yq eval -i -P 'sort_keys(..)' file1.yml
|
||||
yq eval -i -P 'sort_keys(..)' file2.yml
|
||||
yq -i -P 'sort_keys(..)' file1.yml
|
||||
yq -i -P 'sort_keys(..)' file2.yml
|
||||
diff file1.yml file2.yml
|
||||
```
|
||||
|
||||
Note that `yq` does not yet consider anchors when sorting by keys - this may result in invalid yaml documents if your are using merge anchors.
|
||||
|
||||
## Sort keys of map
|
||||
Given a sample.yml file of:
|
||||
```yaml
|
||||
@@ -19,7 +21,7 @@ b: bing
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq eval 'sort_keys(.)' sample.yml
|
||||
yq 'sort_keys(.)' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
@@ -49,7 +51,7 @@ aParent:
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq eval 'sort_keys(..)' sample.yml
|
||||
yq 'sort_keys(..)' sample.yml
|
||||
```
|
||||
will output
|
||||
```yaml
|
||||
|
||||
Reference in New Issue
Block a user