Help us understand the problem. What is going on with this article?

Mac環境でsedコマンドを使う時の注意点

MacとCentOS(Ubuntuも?)でsedコマンドの-iオプションの挙動が異なります。
どう違うかなどは以下のmanコマンドで出力されるマニュアルを見てみましょう。

Macのsedコマンド

-i extension
             Edit files in-place, saving backups with the specified extension.  If a zero-length extension is
             given, no backup will be saved.  It is not recommended to give a zero-length extension when in-place
             editing files, as you risk corruption or partial content in situations where disk space is exhausted,
             etc.

CentOSのsedコマンド

-i[SUFFIX], --in-place[=SUFFIX]
              edit files in place (makes backup if extension supplied).  The default operation mode is to break symbolic and
              hard links.  This can be changed with --follow-symlinks and --copy.

ざっくり言うとMacの方はバックアップ用のファイルを作成することが推奨されているため、-iの後に何も記述しないとエラーになります。
よって、Macでsedコマンドを良い感じに使いたいなら、brew installしましょう。
そして、.bashrcにエイリアスを設定しましょう。

$ brew install gnu-sed
$ vim ~/.bashrc
alias sed='gsed'
$ source ~/.bashrc

これで、-iオプションの際にバックアップ用のファイルを指定しないで済みます。(=エラーがなくなる)

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away