sed でのファイルの行削除もしくは置換ではまる。試しにコマンドラインで実行すると、エラーになってハマる。「sed: 1: "simpledateformat.h": unterminated substitute pattern」
だめだと思って、検索色々してやっと実現と思いきや、実は同じ記述を install.sh 内で実行するとうまくいくらしいと気づいて、今に至る。
sed -i 's/namespace std { class locale; }/\/\/namespace std { class locale; }/g' src/main/include/log4cxx/helpers/simpledateformat.h
「s/namespace std { class locale; }/\/\/namespace std { class locale; }/g」の部分は指定行削除「32d」、指定文字列を含む行の削除「/namespace std { class locale; }/d」でも良い筈。
***
以下は、コマンドラインでエラーが出ない方法としてたどり着いたもの。
sed 's/namespace std { class locale; }/\/\/namespace std { class locale; }/g' simpledateformat.h > tmp.txt && mv tmp.txt simpledateformat.h
とやって実現。
「s/namespace std { class locale; }/\/\/namespace std { class locale; }/g」の部分は指定行削除「32d」、指定文字列を含む行の削除「/namespace std { class locale; }/d」でも良いのだけれど、「-i」オプションを付けると、
「sed: 1: "simpledateformat.h": unterminated substitute pattern」
とエラーが出て、実行できない。
(「-i」が無ければ、ちゃんと標準出力に正しく行削除されたものが表示される。)
ちなみに、シンプルにできるんじゃね、と、
sed 's/namespace std { class locale; }/\/\/namespace std { class locale; }/g' simpledateformat.h > simpledateformat.h
とやると、0バイトファイルの simpledateformat.h が出来上がる。
参考になったのは以下2つ
https://hydrocul.github.io/wiki/commands/sed.html
https://tutorialmore.com/questions-70040.htm
ログインしてコメントを確認・投稿する