From 28a82e9ae8fe6bb041140b28b7341d5a09f81eb2 Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Mon, 17 Oct 2022 15:03:29 +1100 Subject: [PATCH] Added custom sort map example --- operators/sort-keys.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/operators/sort-keys.md b/operators/sort-keys.md index b5101dc1..36c605d2 100644 --- a/operators/sort-keys.md +++ b/operators/sort-keys.md @@ -12,6 +12,9 @@ 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. +For more advanced sorting, using `to_entries` to convert the map to an array, then sort/process the array as you like (e.g. using `sort_by`) and convert back to a map using `from_entries`. +See [here](https://mikefarah.gitbook.io/yq/operators/entries#custom-sort-map-keys) for an example. + {% hint style="warning" %} Note that versions prior to 4.18 require the 'eval/e' command to be specified.