LoginSignup
2
3

More than 5 years have passed since last update.

よく忘れることだがsedはふたつある

Last updated at Posted at 2016-08-10

ネットでみかける通り sedコマンド使ってもエラーになることや、思い通りにならないことがあってストレスを感じてしまうことがる。

そもそもGNU sedBSD sedが存在している。Macに入っているのはBSD sedである。

参考:
GNUのsedとBSDのsed - さよならインターネット

TL;DR
BSD sedがイケてないのではなく、
GNU sedが独自で拡張正規表現を実装していただけっぽい。

特に -iの挙動の違い
* bash - Sed command find and replace in file and overwrite file doesn't work, it empties the file - Stack Overflow
* linux - Delete whitespace in each begin of line of file, using bash - Stack Overflow

確かに タイトルにlinuxとあるものは、そこで GNU sedであることが暗に示されているということだろうか(これに気づかないとハマる)。

正規表現の扱いの違い
* GNU/BSDでのsedにおける正規表現の扱いの違い

などに注意が必要である。

White spaceも
Macでは [[:space:]] であり、 \s not workである。

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3