vi ,a wonderful editor
This time , I need to globally replace a course code SEG<4 digit code> into SEEM<4 digit code> in a file . But that I only want to replace the string preceding a number , but not other words which contains the string “SEG” . Here is the vi command :
:%s/SEG\([0-9]\)/SEEM\1/g
Now everything inside “\(” and “\)” (i.e. [0-9]) is defined as 1 and that will be kept in the replaced string .
So suppose the original File is like :
SEGA
SEG1234 SATUM
SEGMENTATION
SEG2345
The result document will become :
SEGA
SEEM1234 SATUM
SEGMENTATION
SEEM2345