阅读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 键盘的回收