Make sed ask for confirmation before each replacement?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












32















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

















  • 3





    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






  • 1





    It goes against the basic purpose of sed - to automate editing over a stream.

    – teppic
    Oct 1 '15 at 17:24











  • @teppic not really because you would still have to go find the instances in text files, which sed can do for you. I think the question makes sense, just in case you added the wrong files to a list and wanted to see what file you were editing

    – Kolob Canyon
    Nov 14 '16 at 22:44
















32















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

















  • 3





    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






  • 1





    It goes against the basic purpose of sed - to automate editing over a stream.

    – teppic
    Oct 1 '15 at 17:24











  • @teppic not really because you would still have to go find the instances in text files, which sed can do for you. I think the question makes sense, just in case you added the wrong files to a list and wanted to see what file you were editing

    – Kolob Canyon
    Nov 14 '16 at 22:44














32












32








32


7






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














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?







vim sed






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Sep 5 '11 at 23:53









YuviYuvi

29837




29837







  • 3





    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






  • 1





    It goes against the basic purpose of sed - to automate editing over a stream.

    – teppic
    Oct 1 '15 at 17:24











  • @teppic not really because you would still have to go find the instances in text files, which sed can do for you. I think the question makes sense, just in case you added the wrong files to a list and wanted to see what file you were editing

    – Kolob Canyon
    Nov 14 '16 at 22:44













  • 3





    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






  • 1





    It goes against the basic purpose of sed - to automate editing over a stream.

    – teppic
    Oct 1 '15 at 17:24











  • @teppic not really because you would still have to go find the instances in text files, which sed can do for you. I think the question makes sense, just in case you added the wrong files to a list and wanted to see what file you were editing

    – Kolob Canyon
    Nov 14 '16 at 22:44








3




3





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





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





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




1




1





It goes against the basic purpose of sed - to automate editing over a stream.

– teppic
Oct 1 '15 at 17:24





It goes against the basic purpose of sed - to automate editing over a stream.

– teppic
Oct 1 '15 at 17:24













@teppic not really because you would still have to go find the instances in text files, which sed can do for you. I think the question makes sense, just in case you added the wrong files to a list and wanted to see what file you were editing

– Kolob Canyon
Nov 14 '16 at 22:44






@teppic not really because you would still have to go find the instances in text files, which sed can do for you. I think the question makes sense, just in case you added the wrong files to a list and wanted to see what file you were editing

– Kolob Canyon
Nov 14 '16 at 22:44











3 Answers
3






active

oldest

votes


















33














Doing it with sed would probably not be possible as it's a non-interactive stream editor. Wrapping sed in a script 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



Since it was mentioned in comments below, here's how this would be used on multiple files matching a particular filename globbing pattern in the current directory:



for fname in file*.txt; do
vim -c '%s/PATTERN/REPLACEMENT/gc' -c 'wq' "$fname"
done


Or, if you first want to make sure that the file really contains a line that matches the given pattern first, before performing the substitution,



for fname in file*.txt; do
grep -q 'PATTERN' "$fname" &&
vim -c '%s/PATTERN/REPLACEMENT/gc' -c 'wq' "$fname"
done


The above two shell loops modified into find commands that do the same things but for all files with a particular name somewhere in or under some top-dir directory,



find top-dir -type f -name 'file*.txt' 
-exec vim -c '%s/PATTERN/REPLACEMENT/gc' -c 'wq' ;




find top-dir -type f -name 'file*.txt' 
-exec grep -q 'PATTERN' ;
-exec vim -c '%s/PATTERN/REPLACEMENT/gc' -c 'wq' ;


Or, using the original shell loops and having find feed pathnames into them:



find top-dir -type f -name 'file*.txt' -exec sh -c '
for pathname do
vim -c "%s/PATTERN/REPLACEMENT/gc" -c "wq" "$pathname"
done' sh +




find top-dir -type f -name 'file*.txt' -exec sh -c '
for pathname do
grep -q "PATTERN" "$pathname" &&
vim -c "%s/PATTERN/REPLACEMENT/gc" -c "wq" "$pathname"
done' sh +


You do, in any case, not want to do something like for filename in $( grep -rl ... ) since



  1. it would require that grep finishes running before even starting the first iteration of loop, which is inelegant, and

  2. the pathnames returned by grep would be split into words on whitespaces, and these words would undergo filename globbing (this disqualifies pathnames that contains spaces and special characters).

Related:



  • Understanding the -exec option of `find`





share|improve this answer




















  • 2





    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 '16 at 12:44






  • 10





    for i in $(grep -rl "old"); do vim -c "%s/old/new/gc" -c "wq" "$i"; done

    – tecepe
    Aug 14 '16 at 2:19












  • @tecepe, please convert it to an answer, Thank You.

    – Nishant
    Dec 30 '18 at 6:24






  • 1





    @Nishant It would be a fragile answer as it would disqualify any file containing whitespace in its name or path.

    – Kusalananda
    Dec 30 '18 at 7:32


















7














You can get this by doing such:



:%s/OLD_TEXT/NEW_TEXT/gc


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




















  • 4





    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 '16 at 0:35


















3
















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








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f20161%2fmake-sed-ask-for-confirmation-before-each-replacement%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    33














    Doing it with sed would probably not be possible as it's a non-interactive stream editor. Wrapping sed in a script 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



    Since it was mentioned in comments below, here's how this would be used on multiple files matching a particular filename globbing pattern in the current directory:



    for fname in file*.txt; do
    vim -c '%s/PATTERN/REPLACEMENT/gc' -c 'wq' "$fname"
    done


    Or, if you first want to make sure that the file really contains a line that matches the given pattern first, before performing the substitution,



    for fname in file*.txt; do
    grep -q 'PATTERN' "$fname" &&
    vim -c '%s/PATTERN/REPLACEMENT/gc' -c 'wq' "$fname"
    done


    The above two shell loops modified into find commands that do the same things but for all files with a particular name somewhere in or under some top-dir directory,



    find top-dir -type f -name 'file*.txt' 
    -exec vim -c '%s/PATTERN/REPLACEMENT/gc' -c 'wq' ;




    find top-dir -type f -name 'file*.txt' 
    -exec grep -q 'PATTERN' ;
    -exec vim -c '%s/PATTERN/REPLACEMENT/gc' -c 'wq' ;


    Or, using the original shell loops and having find feed pathnames into them:



    find top-dir -type f -name 'file*.txt' -exec sh -c '
    for pathname do
    vim -c "%s/PATTERN/REPLACEMENT/gc" -c "wq" "$pathname"
    done' sh +




    find top-dir -type f -name 'file*.txt' -exec sh -c '
    for pathname do
    grep -q "PATTERN" "$pathname" &&
    vim -c "%s/PATTERN/REPLACEMENT/gc" -c "wq" "$pathname"
    done' sh +


    You do, in any case, not want to do something like for filename in $( grep -rl ... ) since



    1. it would require that grep finishes running before even starting the first iteration of loop, which is inelegant, and

    2. the pathnames returned by grep would be split into words on whitespaces, and these words would undergo filename globbing (this disqualifies pathnames that contains spaces and special characters).

    Related:



    • Understanding the -exec option of `find`





    share|improve this answer




















    • 2





      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 '16 at 12:44






    • 10





      for i in $(grep -rl "old"); do vim -c "%s/old/new/gc" -c "wq" "$i"; done

      – tecepe
      Aug 14 '16 at 2:19












    • @tecepe, please convert it to an answer, Thank You.

      – Nishant
      Dec 30 '18 at 6:24






    • 1





      @Nishant It would be a fragile answer as it would disqualify any file containing whitespace in its name or path.

      – Kusalananda
      Dec 30 '18 at 7:32















    33














    Doing it with sed would probably not be possible as it's a non-interactive stream editor. Wrapping sed in a script 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



    Since it was mentioned in comments below, here's how this would be used on multiple files matching a particular filename globbing pattern in the current directory:



    for fname in file*.txt; do
    vim -c '%s/PATTERN/REPLACEMENT/gc' -c 'wq' "$fname"
    done


    Or, if you first want to make sure that the file really contains a line that matches the given pattern first, before performing the substitution,



    for fname in file*.txt; do
    grep -q 'PATTERN' "$fname" &&
    vim -c '%s/PATTERN/REPLACEMENT/gc' -c 'wq' "$fname"
    done


    The above two shell loops modified into find commands that do the same things but for all files with a particular name somewhere in or under some top-dir directory,



    find top-dir -type f -name 'file*.txt' 
    -exec vim -c '%s/PATTERN/REPLACEMENT/gc' -c 'wq' ;




    find top-dir -type f -name 'file*.txt' 
    -exec grep -q 'PATTERN' ;
    -exec vim -c '%s/PATTERN/REPLACEMENT/gc' -c 'wq' ;


    Or, using the original shell loops and having find feed pathnames into them:



    find top-dir -type f -name 'file*.txt' -exec sh -c '
    for pathname do
    vim -c "%s/PATTERN/REPLACEMENT/gc" -c "wq" "$pathname"
    done' sh +




    find top-dir -type f -name 'file*.txt' -exec sh -c '
    for pathname do
    grep -q "PATTERN" "$pathname" &&
    vim -c "%s/PATTERN/REPLACEMENT/gc" -c "wq" "$pathname"
    done' sh +


    You do, in any case, not want to do something like for filename in $( grep -rl ... ) since



    1. it would require that grep finishes running before even starting the first iteration of loop, which is inelegant, and

    2. the pathnames returned by grep would be split into words on whitespaces, and these words would undergo filename globbing (this disqualifies pathnames that contains spaces and special characters).

    Related:



    • Understanding the -exec option of `find`





    share|improve this answer




















    • 2





      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 '16 at 12:44






    • 10





      for i in $(grep -rl "old"); do vim -c "%s/old/new/gc" -c "wq" "$i"; done

      – tecepe
      Aug 14 '16 at 2:19












    • @tecepe, please convert it to an answer, Thank You.

      – Nishant
      Dec 30 '18 at 6:24






    • 1





      @Nishant It would be a fragile answer as it would disqualify any file containing whitespace in its name or path.

      – Kusalananda
      Dec 30 '18 at 7:32













    33












    33








    33







    Doing it with sed would probably not be possible as it's a non-interactive stream editor. Wrapping sed in a script 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



    Since it was mentioned in comments below, here's how this would be used on multiple files matching a particular filename globbing pattern in the current directory:



    for fname in file*.txt; do
    vim -c '%s/PATTERN/REPLACEMENT/gc' -c 'wq' "$fname"
    done


    Or, if you first want to make sure that the file really contains a line that matches the given pattern first, before performing the substitution,



    for fname in file*.txt; do
    grep -q 'PATTERN' "$fname" &&
    vim -c '%s/PATTERN/REPLACEMENT/gc' -c 'wq' "$fname"
    done


    The above two shell loops modified into find commands that do the same things but for all files with a particular name somewhere in or under some top-dir directory,



    find top-dir -type f -name 'file*.txt' 
    -exec vim -c '%s/PATTERN/REPLACEMENT/gc' -c 'wq' ;




    find top-dir -type f -name 'file*.txt' 
    -exec grep -q 'PATTERN' ;
    -exec vim -c '%s/PATTERN/REPLACEMENT/gc' -c 'wq' ;


    Or, using the original shell loops and having find feed pathnames into them:



    find top-dir -type f -name 'file*.txt' -exec sh -c '
    for pathname do
    vim -c "%s/PATTERN/REPLACEMENT/gc" -c "wq" "$pathname"
    done' sh +




    find top-dir -type f -name 'file*.txt' -exec sh -c '
    for pathname do
    grep -q "PATTERN" "$pathname" &&
    vim -c "%s/PATTERN/REPLACEMENT/gc" -c "wq" "$pathname"
    done' sh +


    You do, in any case, not want to do something like for filename in $( grep -rl ... ) since



    1. it would require that grep finishes running before even starting the first iteration of loop, which is inelegant, and

    2. the pathnames returned by grep would be split into words on whitespaces, and these words would undergo filename globbing (this disqualifies pathnames that contains spaces and special characters).

    Related:



    • Understanding the -exec option of `find`





    share|improve this answer















    Doing it with sed would probably not be possible as it's a non-interactive stream editor. Wrapping sed in a script 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



    Since it was mentioned in comments below, here's how this would be used on multiple files matching a particular filename globbing pattern in the current directory:



    for fname in file*.txt; do
    vim -c '%s/PATTERN/REPLACEMENT/gc' -c 'wq' "$fname"
    done


    Or, if you first want to make sure that the file really contains a line that matches the given pattern first, before performing the substitution,



    for fname in file*.txt; do
    grep -q 'PATTERN' "$fname" &&
    vim -c '%s/PATTERN/REPLACEMENT/gc' -c 'wq' "$fname"
    done


    The above two shell loops modified into find commands that do the same things but for all files with a particular name somewhere in or under some top-dir directory,



    find top-dir -type f -name 'file*.txt' 
    -exec vim -c '%s/PATTERN/REPLACEMENT/gc' -c 'wq' ;




    find top-dir -type f -name 'file*.txt' 
    -exec grep -q 'PATTERN' ;
    -exec vim -c '%s/PATTERN/REPLACEMENT/gc' -c 'wq' ;


    Or, using the original shell loops and having find feed pathnames into them:



    find top-dir -type f -name 'file*.txt' -exec sh -c '
    for pathname do
    vim -c "%s/PATTERN/REPLACEMENT/gc" -c "wq" "$pathname"
    done' sh +




    find top-dir -type f -name 'file*.txt' -exec sh -c '
    for pathname do
    grep -q "PATTERN" "$pathname" &&
    vim -c "%s/PATTERN/REPLACEMENT/gc" -c "wq" "$pathname"
    done' sh +


    You do, in any case, not want to do something like for filename in $( grep -rl ... ) since



    1. it would require that grep finishes running before even starting the first iteration of loop, which is inelegant, and

    2. the pathnames returned by grep would be split into words on whitespaces, and these words would undergo filename globbing (this disqualifies pathnames that contains spaces and special characters).

    Related:



    • Understanding the -exec option of `find`






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Dec 30 '18 at 7:51

























    answered Sep 7 '11 at 15:26









    KusalanandaKusalananda

    123k16232381




    123k16232381







    • 2





      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 '16 at 12:44






    • 10





      for i in $(grep -rl "old"); do vim -c "%s/old/new/gc" -c "wq" "$i"; done

      – tecepe
      Aug 14 '16 at 2:19












    • @tecepe, please convert it to an answer, Thank You.

      – Nishant
      Dec 30 '18 at 6:24






    • 1





      @Nishant It would be a fragile answer as it would disqualify any file containing whitespace in its name or path.

      – Kusalananda
      Dec 30 '18 at 7:32












    • 2





      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 '16 at 12:44






    • 10





      for i in $(grep -rl "old"); do vim -c "%s/old/new/gc" -c "wq" "$i"; done

      – tecepe
      Aug 14 '16 at 2:19












    • @tecepe, please convert it to an answer, Thank You.

      – Nishant
      Dec 30 '18 at 6:24






    • 1





      @Nishant It would be a fragile answer as it would disqualify any file containing whitespace in its name or path.

      – Kusalananda
      Dec 30 '18 at 7:32







    2




    2





    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 '16 at 12:44





    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 '16 at 12:44




    10




    10





    for i in $(grep -rl "old"); do vim -c "%s/old/new/gc" -c "wq" "$i"; done

    – tecepe
    Aug 14 '16 at 2:19






    for i in $(grep -rl "old"); do vim -c "%s/old/new/gc" -c "wq" "$i"; done

    – tecepe
    Aug 14 '16 at 2:19














    @tecepe, please convert it to an answer, Thank You.

    – Nishant
    Dec 30 '18 at 6:24





    @tecepe, please convert it to an answer, Thank You.

    – Nishant
    Dec 30 '18 at 6:24




    1




    1





    @Nishant It would be a fragile answer as it would disqualify any file containing whitespace in its name or path.

    – Kusalananda
    Dec 30 '18 at 7:32





    @Nishant It would be a fragile answer as it would disqualify any file containing whitespace in its name or path.

    – Kusalananda
    Dec 30 '18 at 7:32













    7














    You can get this by doing such:



    :%s/OLD_TEXT/NEW_TEXT/gc


    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




















    • 4





      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 '16 at 0:35















    7














    You can get this by doing such:



    :%s/OLD_TEXT/NEW_TEXT/gc


    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




















    • 4





      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 '16 at 0:35













    7












    7








    7







    You can get this by doing such:



    :%s/OLD_TEXT/NEW_TEXT/gc


    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















    You can get this by doing such:



    :%s/OLD_TEXT/NEW_TEXT/gc


    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














    share|improve this answer



    share|improve this answer








    edited Oct 1 '15 at 16:12









    Community

    1




    1










    answered Oct 7 '11 at 18:30









    Kevin MKevin M

    1,72211212




    1,72211212







    • 4





      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 '16 at 0:35












    • 4





      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 '16 at 0:35







    4




    4





    To clarify: this only works in Vim, not regular command line sed.

    – Brendan
    Oct 1 '15 at 15:28





    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 '16 at 0:35





    The OP is tagged with vim, so this answer is applicable; though, clearly vim and sed have different abilities

    – ILMostro_7
    Mar 13 '16 at 0:35











    3
















    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



























      3
















      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

























        3












        3








        3









        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















        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












        share|improve this answer



        share|improve this answer










        answered Mar 13 '16 at 0:19









        phkphk

        3,98652153




        3,98652153



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f20161%2fmake-sed-ask-for-confirmation-before-each-replacement%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown






            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay