开发者

replace string rsubmit with * rsubmit

I have text files with lines like these:

--------------------------  
.... 
... rsubmit;  
........  
........ endrsubmit;  
.......  
...... rsubmit ;  
................  
....... endrsubmit ;  
..........  
-----------------------------  

I want to replace  
all 'rsubmit;'     with '* rsubmi开发者_运维知识库t;'  
all 'rsubmit ;'    with '* rsubmit ;'  
all 'endrsubmit;'  with '* endrsubmit;'  
all 'endrsubmit ;' with '* endrsubmit ;'  

In short, just put star-space at the beginning.

I have tried to use sed 's/rsubmit\;/\* rsubmit\;/g'

but this method cannot take care of those 'endrsubmit'

Can any one help on this ?

Thanks

Alvin SIU


Try this

sed 's/\(end\)\?rsubmit/* &/' 


Ruby(1.9+)

$ ruby -ne 'print $_.gsub(/(.[^ \t]*rsubmit)/,"*\\1")' file
--------------------------
....
...* rsubmit;
........
........* endrsubmit;
.......
......* rsubmit ;
................
.......* endrsubmit ;
..........
-----------------------------

Or awk

$ awk '{for(i=1;i<=NF;i++) { if ($i~/rsubmit/) { $i="* "$i } } }1' file
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜