8wDlpd.png
8wDFp9.png
8wDEOx.png
8wDMfH.png
8wDKte.png

YQ-如果匹配列表中的至少一个元素,如何按字段值过滤数组

user25653727 3月前

159 0

具体来说(https://github.com/mikefarah/yq)4.35+我有一个以逗号分隔的术语字符串,并且如果字段值是其中一个术语,我想过滤列表。例如)给定以下输入:-

具体来说 https://github.com/mikefarah/yq https://github.com/mikefarah/yq)4.35+

我有一个以逗号分隔的术语字符串,如果字段值是这些术语之一,我想过滤列表。

例如)给定以下输入:

- name: bob
  age: 12
- name: jen
  age: 22
- name: mork
  age: 4003

字段值作为子字符串存在的 name 元素 "jen,mork" 使得输出为:

- name: jen
  age: 22
- name: mork
  age: 4003

我还可以将这些术语表示为字符串数组,即 ["jen", "mork"]

因此相当于:

yq 'filter("jen,mork" | contains(.name))' array.yaml
# Though I'm not sure how `contains` gets the original array context
# or
yq 'filter(.name in ["jen", "mork"])' array.yaml

我意识到这可以通过构建一个集合来完成 or ,如下所示:

yq 'filter(.name == "jen" or .name == "mork"])' array.yaml

但我希望得到一些更优雅的东西。

我不太确定该尝试什么,因为这似乎与操作员想要的工作方式背道而驰。

帖子版权声明 1、本帖标题:YQ-如果匹配列表中的至少一个元素,如何按字段值过滤数组
    本站网址:http://xjnalaquan.com/
2、本网站的资源部分来源于网络,如有侵权,请联系站长进行删除处理。
3、会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。
4、本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报
5、站长邮箱:yeweds@126.com 除非注明,本帖由user25653727在本站《arrays》版块原创发布, 转载请注明出处!
最新回复 (0)
  • 将 Azure blob 内容复制到具有特定结构的本地服务器

    您可以使用 Azcopy 工具将 Azure Blob 内容复制到具有特定结构的本地服务器来实现此目的。

    命令如下:

    azcopy copy "https://venkat326123.blob.core.windows.net/prod/backup/node1/*?<Your-sas-token>" "C:\backup\cluster" --recursive=true
    
    azcopy copy "https://venkat326123.blob.core.windows.net/prod/backup/node2/results/forests/*?<Your-sas-token>" "C:\backup\cluster\forests" --recursive=true
    
    azcopy copy "https://venkat326123.blob.core.windows.net/prod/backup/node3/example/forests/*?<Your-sas-token>" "C:\backup\cluster\forests" --recursive=true
    

    命令和输出:

    PS C:\Users\xxxx> azcopy copy "https://venkat326123.blob.core.windows.net/prod/backup/node1/*?<Your-sas-token>" "C:\backup\cluster" --recursive=true
    INFO: Scanning...
    INFO: azcopy.exe 10.22.2: A newer version 10.25.1 is available to download
    
    INFO: Any empty folders will not be processed, because source and/or destination doesn't have full folder support
    
    Job ea769875-1zzzd3e0c7ef4 has started
    Log file is located at: C:\Users\zzzz.azcopy\ea7698xxx-884d-5166-71ad3e0c7ef4.log
    
    100.0 %, 3 Done, 0 Failed, 0 Pending, 0 Skipped, 3 Total, 2-sec Throughput (Mb/s): 0.0633
    
    
    Job ea769875-15zzzzsummary
    Elapsed Time (Minutes): 0.0334
    Number of File Transfers: 3
    Number of Folder Property Transfers: 0
    Number of Symlink Transfers: 0
    Total Number of Transfers: 3
    Number of File Transfers Completed: 3
    Number of Folder Transfers Completed: 0
    Number of File Transfers Failed: 0
    Number of Folder Transfers Failed: 0
    Number of File Transfers Skipped: 0
    Number of Folder Transfers Skipped: 0
    TotalBytesTransferred: 15823
    Final Job Status: Completed
    
    PS C:\Users\zzzz>  azcopy copy "https://venkat326123.blob.core.windows.net/prod/backup/node2/results/forests/*?<Your-sas-token>" "C:\backup\cluster\forests" --recursive=true
    
    INFO: Scanning...
    INFO: azcopy.exe 10.22.2: A newer version 10.25.1 is available to download
    
    INFO: Any empty folders will not be processed, because source and/or destination doesn't have full folder support
    
    Job 3b63fezzzzz9c50ce has started
    Log file is located at: C:\Users\zzz\.azcopy\3b63xxxxxf-0445-4e19-c116a29c50ce.log
    
    100.0 %, 4 Done, 0 Failed, 0 Pending, 0 Skipped, 4 Total, 2-sec Throughput (Mb/s): 0.0396
    
    
    Job 3b63fe9d-czzz29c50ce summary
    Elapsed Time (Minutes): 0.0335
    Number of File Transfers: 4
    Number of Folder Property Transfers: 0
    Number of Symlink Transfers: 0
    Total Number of Transfers: 4
    Number of File Transfers Completed: 4
    Number of Folder Transfers Completed: 0
    Number of File Transfers Failed: 0
    Number of Folder Transfers Failed: 0
    Number of File Transfers Skipped: 0
    Number of Folder Transfers Skipped: 0
    TotalBytesTransferred: 9940
    Final Job Status: Completed
    
    PS C:\Users\zzz> azcopy copy "https://venkat326123.blob.core.windows.net/prod/backup/node3/example/forests/*?<Your-sas-token>" "C:\backup\cluster\forests" --recursive=true
    INFO: Scanning...
    INFO: azcopy.exe 10.22.2: A newer version 10.25.1 is available to download
    
    INFO: Any empty folders will not be processed, because source and/or destination doesn't have full folder support
    
    Job 176d8769-bec9-184zzzc9 has started
    Log file is located at: C:\Users\zzzzu\.azcopy\176zzec9-1846-zz.log
    
    100.0 %, 3 Done, 0 Failed, 0 Pending, 0 Skipped, 3 Total, 2-sec Throughput (Mb/s): 0.5394
    
    
    Job 176d8769zzcf46a460c9 summary
    Elapsed Time (Minutes): 0.0336
    Number of File Transfers: 3
    Number of Folder Property Transfers: 0
    Number of Symlink Transfers: 0
    Total Number of Transfers: 3
    Number of File Transfers Completed: 3
    Number of Folder Transfers Completed: 0
    Number of File Transfers Failed: 0
    Number of Folder Transfers Failed: 0
    Number of File Transfers Skipped: 0
    Number of Folder Transfers Skipped: 0
    TotalBytesTransferred: 135843
    Final Job Status: Completed
    

    在 Cluster 文件夹中:

    enter image description here

    在森林文件夹中:

    enter image description here

    参考: azcopy copy | Microsoft Learn

返回
作者最近主题: