diff showing only differences inside line
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 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
(the difference between them is the case of letter b
)
I want the output to be something like:
[-b-]{+B+}
Currently, the best approach I found was to use git diff --word-diff
, but it outputs the whole line:
a [-b-]{+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
add a comment |
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 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
(the difference between them is the case of letter b
)
I want the output to be something like:
[-b-]{+B+}
Currently, the best approach I found was to use git diff --word-diff
, but it outputs the whole line:
a [-b-]{+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
It would be nice if you used an example where the differences were more visible. I had to squint to see that those two characters are not the same.
– Barmar
11 hours ago
Sorry, I added a note describing the difference between the lines.
– anol
11 hours ago
Why not just useb
andB
so it's obvious? I understand that this was probably the actual difference, but for purposes of the question you can make it easier.
– Barmar
11 hours ago
1
I wanted to avoid solutions that would only work on ASCII characters, but since the proposed solution does not depend on it, I changed it. However, I cannot update the answer to reflect the new changes since the edit would be smaller than 6 characters long.
– anol
10 hours ago
add a comment |
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 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
(the difference between them is the case of letter b
)
I want the output to be something like:
[-b-]{+B+}
Currently, the best approach I found was to use git diff --word-diff
, but it outputs the whole line:
a [-b-]{+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
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 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
(the difference between them is the case of letter b
)
I want the output to be something like:
[-b-]{+B+}
Currently, the best approach I found was to use git diff --word-diff
, but it outputs the whole line:
a [-b-]{+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
shell-script diff
edited 10 hours ago
anol
asked 20 hours ago
anolanol
381411
381411
It would be nice if you used an example where the differences were more visible. I had to squint to see that those two characters are not the same.
– Barmar
11 hours ago
Sorry, I added a note describing the difference between the lines.
– anol
11 hours ago
Why not just useb
andB
so it's obvious? I understand that this was probably the actual difference, but for purposes of the question you can make it easier.
– Barmar
11 hours ago
1
I wanted to avoid solutions that would only work on ASCII characters, but since the proposed solution does not depend on it, I changed it. However, I cannot update the answer to reflect the new changes since the edit would be smaller than 6 characters long.
– anol
10 hours ago
add a comment |
It would be nice if you used an example where the differences were more visible. I had to squint to see that those two characters are not the same.
– Barmar
11 hours ago
Sorry, I added a note describing the difference between the lines.
– anol
11 hours ago
Why not just useb
andB
so it's obvious? I understand that this was probably the actual difference, but for purposes of the question you can make it easier.
– Barmar
11 hours ago
1
I wanted to avoid solutions that would only work on ASCII characters, but since the proposed solution does not depend on it, I changed it. However, I cannot update the answer to reflect the new changes since the edit would be smaller than 6 characters long.
– anol
10 hours ago
It would be nice if you used an example where the differences were more visible. I had to squint to see that those two characters are not the same.
– Barmar
11 hours ago
It would be nice if you used an example where the differences were more visible. I had to squint to see that those two characters are not the same.
– Barmar
11 hours ago
Sorry, I added a note describing the difference between the lines.
– anol
11 hours ago
Sorry, I added a note describing the difference between the lines.
– anol
11 hours ago
Why not just use
b
and B
so it's obvious? I understand that this was probably the actual difference, but for purposes of the question you can make it easier.– Barmar
11 hours ago
Why not just use
b
and B
so it's obvious? I understand that this was probably the actual difference, but for purposes of the question you can make it easier.– Barmar
11 hours ago
1
1
I wanted to avoid solutions that would only work on ASCII characters, but since the proposed solution does not depend on it, I changed it. However, I cannot update the answer to reflect the new changes since the edit would be smaller than 6 characters long.
– anol
10 hours ago
I wanted to avoid solutions that would only work on ASCII characters, but since the proposed solution does not depend on it, I changed it. However, I cannot update the answer to reflect the new changes since the edit would be smaller than 6 characters long.
– anol
10 hours ago
add a comment |
1 Answer
1
active
oldest
votes
Using wdiff:
$ wdiff -3 a.txt b.txt
======================================================================
[-b-] {+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-] {+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.
It might be worth noting that if your terminal supports ANSI escapes, you can make wdiff print fancy colored output that's (imo) easier to read with this in your bashrc:alias wdiff="wdiff -n -w $'33[30;41m' -x $'33[0m' -y $'33[30;42m' -z $'33[0m'"
(taken from here).
– scohe001
11 hours ago
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Using wdiff:
$ wdiff -3 a.txt b.txt
======================================================================
[-b-] {+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-] {+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.
It might be worth noting that if your terminal supports ANSI escapes, you can make wdiff print fancy colored output that's (imo) easier to read with this in your bashrc:alias wdiff="wdiff -n -w $'33[30;41m' -x $'33[0m' -y $'33[30;42m' -z $'33[0m'"
(taken from here).
– scohe001
11 hours ago
add a comment |
Using wdiff:
$ wdiff -3 a.txt b.txt
======================================================================
[-b-] {+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-] {+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.
It might be worth noting that if your terminal supports ANSI escapes, you can make wdiff print fancy colored output that's (imo) easier to read with this in your bashrc:alias wdiff="wdiff -n -w $'33[30;41m' -x $'33[0m' -y $'33[30;42m' -z $'33[0m'"
(taken from here).
– scohe001
11 hours ago
add a comment |
Using wdiff:
$ wdiff -3 a.txt b.txt
======================================================================
[-b-] {+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-] {+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.
Using wdiff:
$ wdiff -3 a.txt b.txt
======================================================================
[-b-] {+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-] {+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.
edited 10 hours ago
answered 20 hours ago
KusalanandaKusalananda
124k16236388
124k16236388
It might be worth noting that if your terminal supports ANSI escapes, you can make wdiff print fancy colored output that's (imo) easier to read with this in your bashrc:alias wdiff="wdiff -n -w $'33[30;41m' -x $'33[0m' -y $'33[30;42m' -z $'33[0m'"
(taken from here).
– scohe001
11 hours ago
add a comment |
It might be worth noting that if your terminal supports ANSI escapes, you can make wdiff print fancy colored output that's (imo) easier to read with this in your bashrc:alias wdiff="wdiff -n -w $'33[30;41m' -x $'33[0m' -y $'33[30;42m' -z $'33[0m'"
(taken from here).
– scohe001
11 hours ago
It might be worth noting that if your terminal supports ANSI escapes, you can make wdiff print fancy colored output that's (imo) easier to read with this in your bashrc:
alias wdiff="wdiff -n -w $'33[30;41m' -x $'33[0m' -y $'33[30;42m' -z $'33[0m'"
(taken from here).– scohe001
11 hours ago
It might be worth noting that if your terminal supports ANSI escapes, you can make wdiff print fancy colored output that's (imo) easier to read with this in your bashrc:
alias wdiff="wdiff -n -w $'33[30;41m' -x $'33[0m' -y $'33[30;42m' -z $'33[0m'"
(taken from here).– scohe001
11 hours ago
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
It would be nice if you used an example where the differences were more visible. I had to squint to see that those two characters are not the same.
– Barmar
11 hours ago
Sorry, I added a note describing the difference between the lines.
– anol
11 hours ago
Why not just use
b
andB
so it's obvious? I understand that this was probably the actual difference, but for purposes of the question you can make it easier.– Barmar
11 hours ago
1
I wanted to avoid solutions that would only work on ASCII characters, but since the proposed solution does not depend on it, I changed it. However, I cannot update the answer to reflect the new changes since the edit would be smaller than 6 characters long.
– anol
10 hours ago