Any way to change the tab size of the diff command's output?

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











up vote
0
down vote

favorite












I'm on OSX and running a diff command like this, to create side-by-side output:



$] diff -Bbwy --width=200 --suppress-common-lines file1.txt file2.txt > diff-output.txt


It outputs my diffs just fine, but it uses tabs for indentation of the output (alignment of the side-by-side middle line, etc). Additionally, the files in question also use tabs for indentation inside them, so the diff output has all these tab characters in them.



I want the output of diff to have spaces, specifically 4-space's instead of tabs.



I know diff supports the -t option to do just that, but the problem is it uses a fixed size of 8-spaces for all tabs (not only the leading line indentation tabs from the original files, but also its alignment tabs to keep the middle line aligned, etc).



I've tried a variety of post-processing approaches to take the tabs (or spaces) from diff output and shrink them to the desired size of 4-spaces, but that always just causes mis-alignments of the diff side-by-side output.



Then I thought maybe I could pre-process the two files being diffed, using tab2space or something like that, to get each file's line indentations from tabs to 4-spaces before diffing. But I can't work out how, without temporary files, to then get both of those pre-processed inputs piped into diff.



Can that be done?



Or is there any other approach I've not tried? Any secret way to config/force diff -t to just use 4-space tabs instead of 8?







share|improve this question




















  • BTW, I believe that -bw is redundant. Do you find that it behaves differently from -b?
    – G-Man
    Nov 5 '17 at 19:51










  • I don't know that I'm seeing any difference between -b, -w, and -bw, but they seemed like they could be different as they're listed separately. Shrugs.
    – Kyle Simpson
    Nov 6 '17 at 20:45














up vote
0
down vote

favorite












I'm on OSX and running a diff command like this, to create side-by-side output:



$] diff -Bbwy --width=200 --suppress-common-lines file1.txt file2.txt > diff-output.txt


It outputs my diffs just fine, but it uses tabs for indentation of the output (alignment of the side-by-side middle line, etc). Additionally, the files in question also use tabs for indentation inside them, so the diff output has all these tab characters in them.



I want the output of diff to have spaces, specifically 4-space's instead of tabs.



I know diff supports the -t option to do just that, but the problem is it uses a fixed size of 8-spaces for all tabs (not only the leading line indentation tabs from the original files, but also its alignment tabs to keep the middle line aligned, etc).



I've tried a variety of post-processing approaches to take the tabs (or spaces) from diff output and shrink them to the desired size of 4-spaces, but that always just causes mis-alignments of the diff side-by-side output.



Then I thought maybe I could pre-process the two files being diffed, using tab2space or something like that, to get each file's line indentations from tabs to 4-spaces before diffing. But I can't work out how, without temporary files, to then get both of those pre-processed inputs piped into diff.



Can that be done?



Or is there any other approach I've not tried? Any secret way to config/force diff -t to just use 4-space tabs instead of 8?







share|improve this question




















  • BTW, I believe that -bw is redundant. Do you find that it behaves differently from -b?
    – G-Man
    Nov 5 '17 at 19:51










  • I don't know that I'm seeing any difference between -b, -w, and -bw, but they seemed like they could be different as they're listed separately. Shrugs.
    – Kyle Simpson
    Nov 6 '17 at 20:45












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm on OSX and running a diff command like this, to create side-by-side output:



$] diff -Bbwy --width=200 --suppress-common-lines file1.txt file2.txt > diff-output.txt


It outputs my diffs just fine, but it uses tabs for indentation of the output (alignment of the side-by-side middle line, etc). Additionally, the files in question also use tabs for indentation inside them, so the diff output has all these tab characters in them.



I want the output of diff to have spaces, specifically 4-space's instead of tabs.



I know diff supports the -t option to do just that, but the problem is it uses a fixed size of 8-spaces for all tabs (not only the leading line indentation tabs from the original files, but also its alignment tabs to keep the middle line aligned, etc).



I've tried a variety of post-processing approaches to take the tabs (or spaces) from diff output and shrink them to the desired size of 4-spaces, but that always just causes mis-alignments of the diff side-by-side output.



Then I thought maybe I could pre-process the two files being diffed, using tab2space or something like that, to get each file's line indentations from tabs to 4-spaces before diffing. But I can't work out how, without temporary files, to then get both of those pre-processed inputs piped into diff.



Can that be done?



Or is there any other approach I've not tried? Any secret way to config/force diff -t to just use 4-space tabs instead of 8?







share|improve this question












I'm on OSX and running a diff command like this, to create side-by-side output:



$] diff -Bbwy --width=200 --suppress-common-lines file1.txt file2.txt > diff-output.txt


It outputs my diffs just fine, but it uses tabs for indentation of the output (alignment of the side-by-side middle line, etc). Additionally, the files in question also use tabs for indentation inside them, so the diff output has all these tab characters in them.



I want the output of diff to have spaces, specifically 4-space's instead of tabs.



I know diff supports the -t option to do just that, but the problem is it uses a fixed size of 8-spaces for all tabs (not only the leading line indentation tabs from the original files, but also its alignment tabs to keep the middle line aligned, etc).



I've tried a variety of post-processing approaches to take the tabs (or spaces) from diff output and shrink them to the desired size of 4-spaces, but that always just causes mis-alignments of the diff side-by-side output.



Then I thought maybe I could pre-process the two files being diffed, using tab2space or something like that, to get each file's line indentations from tabs to 4-spaces before diffing. But I can't work out how, without temporary files, to then get both of those pre-processed inputs piped into diff.



Can that be done?



Or is there any other approach I've not tried? Any secret way to config/force diff -t to just use 4-space tabs instead of 8?









share|improve this question











share|improve this question




share|improve this question










asked Nov 5 '17 at 18:05









Kyle Simpson

1033




1033











  • BTW, I believe that -bw is redundant. Do you find that it behaves differently from -b?
    – G-Man
    Nov 5 '17 at 19:51










  • I don't know that I'm seeing any difference between -b, -w, and -bw, but they seemed like they could be different as they're listed separately. Shrugs.
    – Kyle Simpson
    Nov 6 '17 at 20:45
















  • BTW, I believe that -bw is redundant. Do you find that it behaves differently from -b?
    – G-Man
    Nov 5 '17 at 19:51










  • I don't know that I'm seeing any difference between -b, -w, and -bw, but they seemed like they could be different as they're listed separately. Shrugs.
    – Kyle Simpson
    Nov 6 '17 at 20:45















BTW, I believe that -bw is redundant. Do you find that it behaves differently from -b?
– G-Man
Nov 5 '17 at 19:51




BTW, I believe that -bw is redundant. Do you find that it behaves differently from -b?
– G-Man
Nov 5 '17 at 19:51












I don't know that I'm seeing any difference between -b, -w, and -bw, but they seemed like they could be different as they're listed separately. Shrugs.
– Kyle Simpson
Nov 6 '17 at 20:45




I don't know that I'm seeing any difference between -b, -w, and -bw, but they seemed like they could be different as they're listed separately. Shrugs.
– Kyle Simpson
Nov 6 '17 at 20:45










1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted











diff (options) <(expand -t4 file1.txt) <(expand -t4 file2.txt)
will expand tabs in the input file to spaces,
assuming tab stops set every four columns. 
Combining this with diff’s -t option should get you what you want.




share|improve this answer




















  • Awesome, that worked perfectly. I was trying | and had completely forgotten about <. :)
    – Kyle Simpson
    Nov 6 '17 at 20:35










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',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
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%2f402696%2fany-way-to-change-the-tab-size-of-the-diff-commands-output%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted











diff (options) <(expand -t4 file1.txt) <(expand -t4 file2.txt)
will expand tabs in the input file to spaces,
assuming tab stops set every four columns. 
Combining this with diff’s -t option should get you what you want.




share|improve this answer




















  • Awesome, that worked perfectly. I was trying | and had completely forgotten about <. :)
    – Kyle Simpson
    Nov 6 '17 at 20:35














up vote
1
down vote



accepted











diff (options) <(expand -t4 file1.txt) <(expand -t4 file2.txt)
will expand tabs in the input file to spaces,
assuming tab stops set every four columns. 
Combining this with diff’s -t option should get you what you want.




share|improve this answer




















  • Awesome, that worked perfectly. I was trying | and had completely forgotten about <. :)
    – Kyle Simpson
    Nov 6 '17 at 20:35












up vote
1
down vote



accepted







up vote
1
down vote



accepted







diff (options) <(expand -t4 file1.txt) <(expand -t4 file2.txt)
will expand tabs in the input file to spaces,
assuming tab stops set every four columns. 
Combining this with diff’s -t option should get you what you want.




share|improve this answer













diff (options) <(expand -t4 file1.txt) <(expand -t4 file2.txt)
will expand tabs in the input file to spaces,
assuming tab stops set every four columns. 
Combining this with diff’s -t option should get you what you want.





share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 5 '17 at 19:51









G-Man

11.6k82657




11.6k82657











  • Awesome, that worked perfectly. I was trying | and had completely forgotten about <. :)
    – Kyle Simpson
    Nov 6 '17 at 20:35
















  • Awesome, that worked perfectly. I was trying | and had completely forgotten about <. :)
    – Kyle Simpson
    Nov 6 '17 at 20:35















Awesome, that worked perfectly. I was trying | and had completely forgotten about <. :)
– Kyle Simpson
Nov 6 '17 at 20:35




Awesome, that worked perfectly. I was trying | and had completely forgotten about <. :)
– Kyle Simpson
Nov 6 '17 at 20:35

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f402696%2fany-way-to-change-the-tab-size-of-the-diff-commands-output%23new-answer', 'question_page');

);

Post as a guest













































































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