How to insert a line in a file between two blocks of known lines (if not already inserted previously), using bash?

前端 未结 3 517
执念已碎
执念已碎 2020-12-11 06:50

I wrote a bash script which can modify php.ini according to my needs.
Now I have to introduce a new change, and I cannot find a clear solution to it.

I need to

3条回答
  •  有刺的猬
    2020-12-11 07:06

    This might work for you:

     sed '/^; Dynamic Extensions ;$/,/^; Module Settings ;$/{H;//{x;/extension="memcache.so"/{p;d};/;;;\n/{s//&extension="memcache.so"\n/p}};d}' file
    

    This will insert extension="memcache.so" between ; Dynamic Extensions ; and ; Module Settings ; unless extension="memcache.so" is already present.

提交回复
热议问题