0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

macでgnu-sedを使う

Last updated at Posted at 2019-03-15

gnu-sedをインストール(元々macにはsedが入っているが、これを使った方がコマンドが簡潔らしいです)
$ brew install gnu-sed

テキストファイルを作成
$ vim fruits.txt

fruits.txt
orange
banana
apple
grape

$ gsed -i “s/orange/orange melon/g” fruits.txt

変更できてるか確認
$ vim fruits.txt

fruits.txt
orange melon
banana
apple
grape

おまけ
.shファイルで更新してみた

$ vim a.sh

a.sh
#!/bin/sh
used -i "s/apple/applepen/g" fruits.txt

を作成して、

$ ./a.sh

を実行

参考:
https://qiita.com/akameco/items/804970cd6655e69cc537
http://blog.katty.in/1352
http://zashikiro.hateblo.jp/entry/2012/09/22/125953

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?