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.
阿神2017-05-16 13:36:05
s
命令前面是确定查找那些行。
问题中/,/
是个正则表达式,表示只要该行中有逗号,那么就执行s命令。 如果你写成1,2s
means only executing the s command on the first and second lines;
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.