这只是一个显示问题的测试文件。原来的部分看起来像这样:
arch systemd[908]:
Run Code Online (Sandbox Code Playgroud)
现在我可以用“:”字符替换右括号
krys@archeos:~/test]$ cat jctl.log | cut -d " " -f 4,5 | head | sed s/]/:/g
arch systemd[908::
Run Code Online (Sandbox Code Playgroud)
当我尝试更换开口支架时,它不起作用:
krys@archeos:~/test]$ cat jctl.log | cut -d " " -f 4,5 | head | sed s/[/:/g
sed: -e expression #1, char 7: unterminated `s' command
Run Code Online (Sandbox Code Playgroud)
然后我用 1 \ 字符转义了“[”,但它仍然不起作用
krys@archeos:~/test]$ cat jctl.log | cut -d " " -f 4,5 | head | sed s/[/:/g
sed: -e expression #1, char 7: unterminated `s' command
Run Code Online (Sandbox Code Playgroud)
使用 2 个“\”即可:
krys@archeos:~/test]$ cat jctl.log …
Run Code Online (Sandbox Code Playgroud) sed ×1