diff showing only differences inside line












2















I want to compare lines in two files, but to minimize noise in the output, I want only the actual differences in the lines to be printed.



For instance, given the two files below:



a.txt



a b c d e f g h i j k l m n o p q r s t u v w x y z


b.txt



a Ь c d e f g h i j k l m n o p q r s t u v w x y z


I want the output to be something like:



[-b-]{+Ь+}


Currently, the best approach I found was to use git diff --word-diff, but it outputs the whole line:



a [-b-]{+Ь+} c d e f g h i j k l m n o p q r s t u v w x y z


Is there a more direct way to do it, other than manually parsing the output? Also, ideally I would prefer to use something more commonly available than git diff, e.g. a POSIX shell tool that would not require the user to install extra packages.










share|improve this question





























    2















    I want to compare lines in two files, but to minimize noise in the output, I want only the actual differences in the lines to be printed.



    For instance, given the two files below:



    a.txt



    a b c d e f g h i j k l m n o p q r s t u v w x y z


    b.txt



    a Ь c d e f g h i j k l m n o p q r s t u v w x y z


    I want the output to be something like:



    [-b-]{+Ь+}


    Currently, the best approach I found was to use git diff --word-diff, but it outputs the whole line:



    a [-b-]{+Ь+} c d e f g h i j k l m n o p q r s t u v w x y z


    Is there a more direct way to do it, other than manually parsing the output? Also, ideally I would prefer to use something more commonly available than git diff, e.g. a POSIX shell tool that would not require the user to install extra packages.










    share|improve this question



























      2












      2








      2








      I want to compare lines in two files, but to minimize noise in the output, I want only the actual differences in the lines to be printed.



      For instance, given the two files below:



      a.txt



      a b c d e f g h i j k l m n o p q r s t u v w x y z


      b.txt



      a Ь c d e f g h i j k l m n o p q r s t u v w x y z


      I want the output to be something like:



      [-b-]{+Ь+}


      Currently, the best approach I found was to use git diff --word-diff, but it outputs the whole line:



      a [-b-]{+Ь+} c d e f g h i j k l m n o p q r s t u v w x y z


      Is there a more direct way to do it, other than manually parsing the output? Also, ideally I would prefer to use something more commonly available than git diff, e.g. a POSIX shell tool that would not require the user to install extra packages.










      share|improve this question
















      I want to compare lines in two files, but to minimize noise in the output, I want only the actual differences in the lines to be printed.



      For instance, given the two files below:



      a.txt



      a b c d e f g h i j k l m n o p q r s t u v w x y z


      b.txt



      a Ь c d e f g h i j k l m n o p q r s t u v w x y z


      I want the output to be something like:



      [-b-]{+Ь+}


      Currently, the best approach I found was to use git diff --word-diff, but it outputs the whole line:



      a [-b-]{+Ь+} c d e f g h i j k l m n o p q r s t u v w x y z


      Is there a more direct way to do it, other than manually parsing the output? Also, ideally I would prefer to use something more commonly available than git diff, e.g. a POSIX shell tool that would not require the user to install extra packages.







      shell-script diff






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 1 hour ago







      anol

















      asked 1 hour ago









      anolanol

      346411




      346411






















          1 Answer
          1






          active

          oldest

          votes


















          4














          Using wdiff:



          $ wdiff -3 a.txt b.txt

          ======================================================================
          [-b-] {+Ь+}
          ======================================================================


          The -3 or ---no-common option will remove words that are common between the two files and only show the differences.



          The ===... banner (and empty lines) may be removed with grep:



          $ wdiff -3 a.txt b.txt | grep -vx '=*'
          [-b-] {+Ь+}


          wdiff may also read unified diff data if you give it the -d or --diff-input option, for example from git:



          git diff somefile | wdiff -d -3


          Although wdiff is not a POSIX tool, it is commonly available.






          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%2f495228%2fdiff-showing-only-differences-inside-line%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            4














            Using wdiff:



            $ wdiff -3 a.txt b.txt

            ======================================================================
            [-b-] {+Ь+}
            ======================================================================


            The -3 or ---no-common option will remove words that are common between the two files and only show the differences.



            The ===... banner (and empty lines) may be removed with grep:



            $ wdiff -3 a.txt b.txt | grep -vx '=*'
            [-b-] {+Ь+}


            wdiff may also read unified diff data if you give it the -d or --diff-input option, for example from git:



            git diff somefile | wdiff -d -3


            Although wdiff is not a POSIX tool, it is commonly available.






            share|improve this answer






























              4














              Using wdiff:



              $ wdiff -3 a.txt b.txt

              ======================================================================
              [-b-] {+Ь+}
              ======================================================================


              The -3 or ---no-common option will remove words that are common between the two files and only show the differences.



              The ===... banner (and empty lines) may be removed with grep:



              $ wdiff -3 a.txt b.txt | grep -vx '=*'
              [-b-] {+Ь+}


              wdiff may also read unified diff data if you give it the -d or --diff-input option, for example from git:



              git diff somefile | wdiff -d -3


              Although wdiff is not a POSIX tool, it is commonly available.






              share|improve this answer




























                4












                4








                4







                Using wdiff:



                $ wdiff -3 a.txt b.txt

                ======================================================================
                [-b-] {+Ь+}
                ======================================================================


                The -3 or ---no-common option will remove words that are common between the two files and only show the differences.



                The ===... banner (and empty lines) may be removed with grep:



                $ wdiff -3 a.txt b.txt | grep -vx '=*'
                [-b-] {+Ь+}


                wdiff may also read unified diff data if you give it the -d or --diff-input option, for example from git:



                git diff somefile | wdiff -d -3


                Although wdiff is not a POSIX tool, it is commonly available.






                share|improve this answer















                Using wdiff:



                $ wdiff -3 a.txt b.txt

                ======================================================================
                [-b-] {+Ь+}
                ======================================================================


                The -3 or ---no-common option will remove words that are common between the two files and only show the differences.



                The ===... banner (and empty lines) may be removed with grep:



                $ wdiff -3 a.txt b.txt | grep -vx '=*'
                [-b-] {+Ь+}


                wdiff may also read unified diff data if you give it the -d or --diff-input option, for example from git:



                git diff somefile | wdiff -d -3


                Although wdiff is not a POSIX tool, it is commonly available.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 42 mins ago

























                answered 51 mins ago









                KusalanandaKusalananda

                124k16235386




                124k16235386






























                    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%2f495228%2fdiff-showing-only-differences-inside-line%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

                    Polycentropodidae

                    Magento 2 Error message: Invalid state change requested

                    Paulmy