传递给 sed 命令的 -n 参数有什么意义? [英] What is the significance of -n parameter passed to sed command?

查看:55
本文介绍了传递给 sed 命令的 -n 参数有什么意义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我 sed -n '1!p 是如何工作的?下面是我用来根据分配的节点对 k8s 中的 pod 进行排序的完整命令.

Can someone please tell me how does sed -n '1!p work ? Below is the full command which I am using to sort my pods in k8s based on nodes they are assigned.

kubectl get pods -o wide --all-namespaces|sort -k8 -r| sed -n '1!p'

上述命令完美运行,sed 部分从最终输出中删除了第一个标题行.

The above command works perfectly and the sed part removes the first header line from the final output.

我想了解 sed 部分是如何工作的,以及传递给 sed 的参数有何意义?

I want to understand how does the sed part work and what's the significance of the parameters passed to sed?

推荐答案

来自 info sed:

-n:默认情况下,'sed' 在每个文件的末尾打印出模式空间循环遍历脚本(*注意sed"的工作原理:执行周期.).这些选项禁用此自动打印,并且仅 'sed'当通过 'p' 命令明确告知时产生输出.

-n: By default, 'sed' prints out the pattern space at the end of each cycle through the script (*note How 'sed' works: Execution Cycle.). These options disable this automatic printing, and 'sed' only produces output when explicitly told to via the 'p' command.

1p:打印第一行

1!p:不打印第一行.

这篇关于传递给 sed 命令的 -n 参数有什么意义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆