我有一个努谢尔查询:
open ./s3_actions.csv | where actions !~ 'Acl' | where actions !~ 'Cors' | where actions !~ 'Job' | where actions !~ 'Retention' | where actions !~ 'Legal' | where actions !~ 'Payment' | where actions !~ 'Policy' | where actions !~ 'Configuration' | where actions !~ 'Replicate' | where actions !~ 'AccessPoint'有没有办法将所有的where actions !~ ...子句合并成一个大列表?
我得到的最接近的是这里,但我不知道如何执行嵌套循环,这两个循环都有相同的$it变量。
发布于 2022-04-30 21:04:13
您没有提供任何可以验证的示例数据,但我假设如下:
actions,element,node,something
Acl Forward Bar Baz,52206,19075,71281
Legal Stack,31210,21366,52576
Configuration Help Doc,13684,65142,78826
Help Doc,48488,44794,93282
Baz Bar Foo,13140,60057,73197
Foo Baz Bar,62892,63836,126728
,64022,54909,118930
Abc,50240,16109,66348
Def Bar Foo,18680,17847,36526
Acl Bar Vegas,55553,22953,78506
Taco Hamburger Sushi,30311,42345,72656您的特定数据源可能有另一种方法,但是下面的行(为了提高可读性而拆分成多行)返回与问题中的多个where子句相同的结果:
open ./s3_actions.csv | where {|it|
(["Acl", "Cors", "Job", "Retention", "Legal", "Payment", "Policy", "Configuration", "Replicate", "AccessPoint"] |
reduce -f true { |action,acc|
($it.actions !~ $action) && $acc
})
}解释:
最终,您所要求的是一种将“where操作列表”降到单个值( true或false )的方法。有关这一点,请查看reduce命令。
在这种情况下:
where返回的每条记录运行s3_actions.csvreduce。它从设置为true的累加器(true)开始,但是如果任何测试返回false,那么当两者都是&& (和)‘ed时,就会变成假的。是的,因为这里有两个块(对于where和reduce),您需要为每个参数使用不同的名称。
发布于 2022-05-02 20:51:20
我可能只是使用&&或and操作符,比如... | where x == y && a == b && z == d
https://stackoverflow.com/questions/71932156
复制相似问题