I wouldn't feel game to run a global search-and-replace when the code is so inconsistent. I would be using grep/vim to check each line, unless you seriously do have 10,000 changes to make. To use grep/vim, the steps would be something like this:
1) Add the following to your .vimrc:
" <f1> looks for SID in the current file
map <f1> /<SID><CR>
" <f2> goes to the next file
map <f2> :next<CR><f1>
" <f5> deletes only the current line, and goes to the next SID
map <f5> dd
" <f6> deletes the current line and the one above, and goes to the next SID
map <f6> k2dd
" <f7> deletes the current line and the one below, and goes to the next SID
map <f7> 2dd
" <f8> deletes the current line, and the one above AND the one below
map <f8> k3dd
2) This grep
command will find all the files you need to change:
grep -rl 'SID' * > fix-these-files.txt
You may need to tweak it slightly to make sure that it is finding all the files you need to change. Make sure it is correct before you go to the next step.
3) Use vim to open all the files that need fixing, like this:
vim '+set confirm' '+/<SID>' $(cat fix-these-files.txt)
4) You should now have vim
open, and looking at the first SID in the first file you need to change. Use the following steps to fix each occurrence of SID:
- If you only need to delete the current line, press
<F5>
.
- If you need to delete the line above at the same time, press
<F6>
instead of <F5>
.
- If you need to delete the line below at the same time, press
<F7>
instead of <F5>
- If you need to delete the lines above and below at the same time, press
<F8>
instead of <F5>
- Press
<F1>
to find an another occurrence of SID to fix.
- When SID cannot be found in the current file any more, press
<F2>
to go to the next file.
Exit vim when there are no more SIDs to be fixed.
5) Check to make sure you got everything, by running the grep
command from step (2) again. There should be no search matches.
6) Delete the extra mappings you added to your .vimrc
in step (1).
Warning: I haven't tested the steps above, if you use them, be careful that you only make exactly the changes you need!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…