search

Home  >  Q&A  >  body text

linux - How to understand sed -n '/,/s/,/ /gp'

I saw this writing in the book

 uptime|sed -n '/,/s/,/ /gp'

I can understand this way of writing sed 's/,/ /gp', but I can't understand the above.

習慣沉默習慣沉默2756 days ago712

reply all(2)I'll reply

  • 阿神

    阿神2017-05-16 13:36:05

    1. s命令前面是确定查找那些行。
      问题中/,/是个正则表达式,表示只要该行中有逗号,那么就执行s命令。 如果你写成1,2s means only executing the s command on the first and second lines;

    2. s命令后面是命令内容: /将要被替换的内容/替换成的内容/, 对应问题中 s/,/ /;

    In summary, find the lines with commas and perform matching: if a comma is matched, replace the comma with a space. As for gp, I won’t explain too much, I believe you understand.

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-16 13:36:05

    Match lines with , , and replace all , with spaces

    reply
    0
  • Cancelreply