What actually the meaning of “-n” in sed?

后端 未结 4 1657
粉色の甜心
粉色の甜心 2021-01-01 23:05

According to http://linux.about.com/od/commands/l/blcmdl1_sed.htm

suppress automatic printing of pattern space

I\'ve tested wi

4条回答
  •  庸人自扰
    2021-01-01 23:59

    This puts sed into quiet mode, where sed will suppress all output except for when explicitly stated by a p command:

       -n 
       --quiet 
       --silent
              By default, sed will print out the pattern space at
              the  end  of  each cycle through the script.  These
              options disable this automatic  printing,  and  sed
              will  only  produce  output when explicitly told to
              via the p command.
    

    An example of this would be if you wanted to use sed to simulate the actions of grep:

    $echo -e "a\nb\nc" | sed -n '/[ab]/ p'
    a
    b
    

    without the -n you would get an occurrence of c (and two occurrences of a and b)

提交回复
热议问题