下面是我的测试。如何修复错误?
ubuntu@u1804:~# sed --version
sed (GNU sed) 4.5
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Jay Fenlason, Tom Lord, Ken Pizzini,
and Paolo Bonzini.
GNU sed home page: <https://www.gnu.org/software/sed/>.
General help using GNU software: <https://www.gnu.org/gethelp/>.
E-mail bug reports to: <[email protected]>.
ubuntu@u1804:~#
ubuntu@u1804:~# cat test
11
aa
bb
cc
edde
xx
aa
bb
cc
edde
22
ubuntu@u1804:~# sed -r '/^[a-z]/{s/^.*$/(&)/; w result}' test
sed: -e expression #1, char 0: unmatched `{'
ubuntu@u1804:~#
ubuntu@u1804:~# sed -r '/^[a-z]/{s/^.*$/(&)/; p}' test
11
(aa)
(aa)
(bb)
(bb)
(cc)
(cc)
(edde)
(edde)
(xx)
(xx)
(aa)
(aa)
(bb)
(bb)
(cc)
(cc)
(edde)
(edde)
22
ubuntu@u1804:~#
检查您的工作目录,您可能有一个名为
result}
created的文件有不同的解决方法,其中之一是使用
-e
选项来分隔命令。使用时w
,它后面的所有字符都用于文件名,因此为什么会出现错误,因为{
没有结尾对进一步阅读:GNU sed 手册:需要换行符的命令