linux - How to understand sed -n '/,/s/,/ /gp'
習慣沉默
習慣沉默 2017-05-16 13:34:05
0
2
685

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.

習慣沉默
習慣沉默

reply all(2)
阿神
  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.

过去多啦不再A梦

Match lines with , , and replace all , with spaces

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!