0

I have text files with lines like these:

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

I want to replace  
all 'rsubmit;'     with '* rsubmit;'  
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

kurumi
  • 25,121
  • 5
  • 44
  • 52
Alvin SIU
  • 1,022
  • 10
  • 28

2 Answers2

1

Try this

sed 's/\(end\)\?rsubmit/* &/' 
glenn jackman
  • 238,783
  • 38
  • 220
  • 352
0

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
kurumi
  • 25,121
  • 5
  • 44
  • 52
  • Sorry no ruby in my company. Also, the rsubmit; and endrsubmit; statement may start at the beginning of the line. – Alvin SIU Apr 05 '11 at 09:43