What is the significance of -n parameter passed to sed command?

后端 未结 2 1101
庸人自扰
庸人自扰 2021-01-24 18:38

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.

2条回答
  •  孤独总比滥情好
    2021-01-24 19:18

    By default, sed will output every line it parses.
    -n option is there to hide this output, and display only the lines specified with the p option.

    In your exemple, sed -n '1!p' means "Display every line but first".


    A more understandable example is when you want to search/replace with sed. If you want to see the whole resulting file you'll use this:

    sed 's/from/to/g' file.txt
    

    But if you only want to see which lines have been changed, use this:

    sed -n 's/from/to/gp' file.txt
    

提交回复
热议问题