LoginSignup
0
1

More than 5 years have passed since last update.

ワンライナーで設定ファイルの一部をコメントアウトする

Last updated at Posted at 2019-03-12

こんな設定ファイルがあって対象の行だけワンライナーでコメントアウトしたい

nginx.conf

location hogehoge {
 なんかの設定
}

これでいけた

sed -i '' -e '/hogehoge/,/}/ s/^/ # /g' ./nginx.conf
  • hogehogeで始まって}で終わる行の先頭(正規表現で^)に#をつけるワンライナー

  • macだと-i ''オプションがないとうまくいかない。LinuxであればなくてもOK

(冪等性はともかく)これをAnsibleにshellモジュールで実行させてサーバ設定したりとかできます

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