求助sed的一个使用方法

sh/bash/dash/ksh/zsh等Shell脚本
回复
taug
帖子: 4
注册时间: 2012-07-21 12:50

求助sed的一个使用方法

#1

帖子 taug » 2013-05-24 14:35

相处里一批代码文件,把其中的一行替换为两行,并且保持缩放,比如文件中有一行:

代码: 全选

      System.out(0);
要替换成

代码: 全选

       SceneController.sceneIndex = 0;
	    sceneController.finish();
谷歌了很久没有找到结果,希望各位大神指点以下。
aerofox
帖子: 1453
注册时间: 2008-05-24 8:30

Re: 求助sed的一个使用方法

#2

帖子 aerofox » 2013-05-24 19:43

代码: 全选

sed -r 's/([[:space:]]*)System\.out\(([[:digit:]]+)\)/\1SceneController.sceneIndex = \2;\n\1sceneController.finish();/'
头像
烟雨平生
帖子: 103
注册时间: 2006-07-06 16:35
联系:

Re: 求助sed的一个使用方法

#3

帖子 烟雨平生 » 2013-06-25 11:10

sed '/System.out(0);/cSceneController.sceneIndex = 0;\nsceneController.finish();' file
回复