27
16

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 ] 連続置換とor条件の書き方メモ

Last updated at Posted at 2015-12-21

###1. 連続置換は-e でつなぐ
いろいろやり方はあるが、とりあえずこれだけ覚えておけばよさそう。

cookbook名だけ取り出したいとき
#"recipe["をトル
#"]"をトル
 echo "recipe[sample_cookbook]" | sed -e 's/^"recipe\[//' -e 's/\]"//'
 #=>sample_cookbook

###2. or条件のパイプ|はエスケープして使う
\| <= これ使えばor条件で文字列検索できる

roleがrunlistに入っていたらroleの名前も取りたいとき
##"recipe[か"role[で検索して置換する
 echo "role[sample_cookbook]" | sed -e 's/^"recipe\[\|^role\[//' -e 's/\]"//'
 #=>sample_cookbook
27
16
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
27
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?