閱讀472 返回首頁    go 阿裏雲 go 技術社區[雲棲]


sed 多行替換,多行模式處理字符串;一次替換

作者:凨

例:
需求:sed 替換多行(2到6行)替換為空,且返回係統配置信息

<?php
/**CustomConfigurationStart*/
$c=require APP_PATH.'Common/Conf/config-custom.php';
/*COOKIES,SESSION域*/
$domain=preg_replace('/(.*\.|.*\/\/)?(\w+)\.(\w+)(\/)?$/', '.$2.$3',$c['WWW']);
/**CustomConfigurationEnd*/
/**
 * 係統配文件
 * 所有係統級別的配置
 */
$d=[
.......
];return array_merge($d,$c);
結果:
<?php
/**autoFormatNull*/
/**
 * 係統配文件
 * 所有係統級別的配置
 */
return [
......
];

1.sed替換多行,替換為空或其他字符串autoFormatNull

方法一:
sed -i '2,6d' config.php
方法二:
sed -i ':a;$!{N;ba};s/CustomConfigurationStart.*CustomConfigurationEnd/autoFormatNull/' config.php

2.sed 替換$d=[替換為return [

sed -i 's/\$d=\[/return \[/g' config.php

3.sed 替換末尾數據替換為];

sed -i 's/];return.*array_merge(\$d,\$c);/];/g' config.php


感謝:https://blog.csdn.net/jevens17/article/details/6601368 提供思路

最後更新:2017-04-03 05:39:19

  上一篇:go getElementsByName在IE中取到的對象
  下一篇:go 鍵盤的回收