使用 bash 检查 yaml 文件排序



我有一个描述服务器上目录的yaml文件。我需要一个简短的脚本来检查各部分是否按名称的字母顺序排序。如果某些部分不是按字母顺序插入的,则需要指出应该指定的位置。文件看起来像(路径和权限是可选参数):

-
  name: scripts 
  description: execution scripts
  path: /home/user/scripts
-
  name: tests
  description: directory with tests
  path: /home/user/tests
  permissions: default
...

你能建议最好的方法吗?谢谢

怎么样

$ diff -u <(grep name: yaml) <(grep name: yaml | sort)
--- /dev/fd/11  2016-05-24 20:30:39.000000000 +0200
+++ /dev/fd/12  2016-05-24 20:30:39.000000000 +0200
@@ -1,2 +1,2 @@
-  name: tests
   name: scripts
+  name: tests

文件在哪里yaml

最新更新