I want to apply some regex replacement globally to 40 Javascript files in and under the directory. I am a vim user, but doing it manually can be tedious and error prone, so I would like to automate it with a script.
I tried sed, but processing multiple lines at a time is inconvenient, especially if there is no limit to the number of lines a template can have.
I also tried this script (in one file for testing):
ex $1 <<EOF gs/,\(\_\s*[\]})]\)/\1/ EOF
The template will remove the trailing comma in any Perl / Ruby-style list, so that "[a, b, c,]" will come out as "[a, b, c]" to satisfy Internet Explorer, which alone among browsers suffocates in such lists.
The template works beautifully in vim, but does nothing if I run it in ex, as described above in the script.
Can anyone see what I can lose?
scripting vim regex replace
Lawrence I. siden
source share