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.

sedコマンドを初めて見て、意味不明だったので読解したメモ

Posted at

ある記事を見ているときに、下記のようなコマンドが出現

$ sed -i.bak s@xxx@$HOME/test@ a.txt

sed ってなに

なるほど、文字列の置き換えコマンドなのか、、

参考:
【Linuxコマンド】sedで文字列を置換する方法

-i.bakはなに

-i は直接編集して内容を上書きですぜってわかりましたが
.bak はおそらくその際に.bakファイルを作ってくれるのかな?

@はなにもの

パスなどを全置換する際にスラッシュをエスケープするのが面倒な場合 2013/06/18
s/.../..../g の記法のスラッシュは記号なら比較的なんでもよくて、3つ同じ記号を使っていることに意味があるので、s@...@...@g のようにも書ける。

cat ファイル名 | sed -e 's@/etc/foo/bar@/home/my/etc/foo/bar@g'

参考&引用元:
sedコマンド

/で区切って 置き換えたい文字 / 置き換える文字 って書いてない!?
@って何!?ってなりました。当然のごとく。

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?