Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to make sed ask me for confirmation before each replace? Something similar to 'c' when using replace inside vim.

Does sed do this at all?

share|improve this question
It would be technically possible but more of an intellectual exercise than a useful endeavor. See How to do a text replacement in a big folder hierarchy? which has Vim and Perl solutions. – Gilles Sep 6 '11 at 0:20
I am using vim (args and argdo) whenever I need 'confirmation', but was wondering if there was a 'simpler' way – Yuvi Sep 7 '11 at 19:26
It goes against the basic purpose of sed - to automate editing over a stream. – teppic Oct 1 '15 at 17:24

Doing it with sed would probably be possible but would require far too much thinking. It is easier to just do it with vim:

vim -c '%s/PATTERN/REPLACEMENT/gc' -c 'wq' file.in
share|improve this answer
The advantage to sed is it can operate on multiple files, e.g., sed -i 's/old/new/g' /path/to/*.txt or something similar. – user1717828 May 10 at 12:44

You can get this by doing such:


Specifically, adding the c after the third delimiter.

Note that the 'c' option only works in Vim; you won't be able to use it with sed at the command line.

share|improve this answer
To clarify: this only works in Vim, not regular command line sed. – Brendan Oct 1 '15 at 15:28
The OP is tagged with vim, so this answer is applicable; though, clearly vim and sed have different abilities – ILMostro_7 Mar 13 at 0:35

You could let sed do its thing on the file and then save the result to a temporary file which you can then interactively patch into the original file using sdiff (see http://www.gnu.org/software/diffutils/manual/diffutils.html#Invoking-sdiff):

sed -r 's/something/something_else/g' my_file > tmp_file
sdiff -o my_file -s -d my_file tmp_file
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.