Back again with some more advice.
You might consider using ed
instead. As dedicated text editors, they can update the file directly without the need to work through temporary files. All you need to do is feed them a series of commands separated by newline characters (I like to use printf
for this personally).
is lighter and more portable, but it has the downside that you can't change the "s
" delimiter, so we're back to some picket-fence like strings.
printf '%s\n' 'g/DROP .*;/ s/.*/\/* & *\//' ',p' | ed -s file.txt
" just prints the modified file to stdout. Change it to "w
" to write the changes back to the original file.
How to use ed:
(also read the info page)
works in an nearly identical fashion, and it can
use different delimiters (although not my favorite "|
", which is reserved as a command separator.
, so I'm using "@
" in my example below).
printf '%s\n' 'g/DROP .*;/ s@.*@/* & */@' '%p' | vim -es file.txt
Again, change "%p
" to "w
" to write the changes back to file.
I'm still a bit of a newbie regarding vim though, so I'm not 100% sure I have the best syntax for the command.