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 SIUTry 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
精彩评论