
以下は私のテストです。このエラーをどのように解決できますか?
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:~#
答え1
作業ディレクトリを確認してください。result}
createというファイルがあるかもしれません。
sed -r -e '/^[a-z]/{s/^.*$/(&)/; w result' -e '}' test
さまざまな回避策があり、その1つは-e
オプションを使用してコマンドを区切ることです。使用すると、w
その後のすべての文字がファイル名として使用されるため、閉じる{
ペアがないため、エラーが発生します。