Posix Sed で改行を出力する方法
Published: 2019/4/9
Posix Sed で改行を行う方法が、自明ではなかったのでまとめておく。
$ echo hogehoge | sed -e "$(printf 's/hogehoge/hoge\\\nhoge/g\n')"
hoge
hoge
$
この挙動は、 posix の sed command の説明ページに記載がある。
The application shall escape the <newline> in the replacement by preceding it by a <backslash>.
つまり、 replacement の newline は backslash でクォートするべき、とのこと。
参考: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html
Tags: posixsed
Rubyist のための python 標準 logging モジュールの擬似コード
Rails の Migration で「Lost connection to MySQL server during query」と言われた際の対処方法
関連記事
POSIX Sed のスクリプトの構文等の仕様について
2021/5/13
POSIX における環境変数の仕様について
2021/12/3
pwd とは何かと、cwd やシンボリックリンクとの関係
2021/11/5
POSIX における文字とエンコーディング(ロケール)と正規表現
2021/5/10