将xargs与输出通过管道传输到awk会引发语法错误

问题描述 投票:-2回答:1

团队,我读了很多帖子,但不清楚。.

我需要了解如何处理。。我让xargs进行了一些评估,然后通过管道传递给awk,但出现语法错误

file.log

node1,
node2,
node3,

使用xargs和awk的表达式失败

cat file.log | awk -F ',' '{print $1}' | xargs -l1 -- sh -c 'kubectl get pods --all-namespaces --no-headers --field-selector spec.nodeName=$1 | awk "{if ($1 ~ "team-") print $1,$2}"' --

传递到这里

cat file.log | awk -F ',' '{print $1}' | xargs -l1 -- sh -c 'kubectl get pods --all-namespaces --no-headers --field-selector spec.nodeName=$1

我添加awk part..am一无所获。

输出:

awk: line 1: syntax error at or near )

我发现的替代解决方案是将awk移出xargs-。所以下面的作品。但是我该如何获取awk的内部内容,因为我想打印xargs中使用的$ 1来查看与awk所打印内容的相关性。

WORKS

--field-selector spec.nodeName=$1' -- | awk '{if ($1 ~ "team-") print $1,$2}'

FAILS

--field-selector spec.nodeName=$1 | awk '{if ($1 ~ "team-") print $1,$2}' --

bash awk sed xargs
1个回答
0
投票

使用此posts help找出它..

这是对我有用的。我在dQuotes中引用了awk,然后在$里面转义了$]

cat file.log | awk -F ',' '{print $1}' | xargs -l1 -- sh -c 'kubectl get pods --all-namespaces --no-headers --field-selector spec.nodeName=$1 | awk "{if (\$1 ~ \"team-\") print \$1,\$2}"' --
© www.soinside.com 2019 - 2024. All rights reserved.