Simplified yq usage

This commit is contained in:
Mike Farah
2022-01-28 12:45:43 +11:00
parent e84a50db2e
commit 9896245f71
44 changed files with 515 additions and 316 deletions
+6 -4
View File
@@ -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