Nuggets of Information
From the Quagmire of My Mind...

Just somewhere to dump pearls of wisdom (and sometimes other stuff) from a old, tired nerd that's been doing DevOps and related things for FAR to long :)

TIL: Sed (in VIM) search and replace (with confirmation)

 

Today I was editing a file on a remote linux machine, and wanted to do a search of text, and replace with confirmations, since I didn’t want to replace all instances. That’s pretty simple:

:s/search-text/replace-text/g

but I wanted confirmations of each instance found, if I wanted to replace it or not. So it’s a minor difference:

:%s/search-text/replace-text/gc

This will search for the text, but ask you to make sure you want to replace it. On my instance (with VIM installed) the options where a simple ‘y’ or ‘n’, but in my readings today saw that sometimes (maybe with just vi, and not vim) it’s ‘c’ to confirm the replacement.