0

Ubuntu 16.04
Bash 4.4.0
sdiff (GNU diffutils) 3.3

When I use the command sdiff in shell formatting is perfect

sdiff -w 185 fileone filetwo  

sdiff formatting in shell is perfect

When I use the command sdiff and send the results to a file, formatting disappears

sdiff -w 185 fileone filetwo > filethree

sdiff formatting disappears when output is sent to a file

How can I preserve formatting when I send sdiff output to a file?

7
  • does sdiff -w 185 fileone filetwo -o output works? Apr 11, 2021 at 5:55
  • 2
    use sdiff's -t option to expand tabs to spaces. Alternatively, tell your viewer/editor to set tab stops to 8 spaces - e.g. in vi :set ts=8 or with less, use less -x8.
    – cas
    Apr 11, 2021 at 6:10
  • @αғsнιη I'm afraid not. Apr 11, 2021 at 8:34
  • @Cas This worked on the server sdiff -t -w 185 fileone filetwo > filethree. When a windows webadmin opened the file, it went back to being unformatted. I added an extra command expand -t 2 filethree | sponge filethree and now the file is perfectly formatted. Hats off to you mate. Apr 11, 2021 at 9:13
  • btw, -t should have worked for any viewer, it does exactly what expand does. If you want tabstops every 2 spaces, you can use -t --tabsize 2 with sdiff, no need for expand and sponge.
    – cas
    Apr 11, 2021 at 9:39

1 Answer 1

1

As explained by @cas, to preserve the formatting while sending sdiff output to a file, include -t

sdiff -t -w 185 fileone filetwo > filethree    

To control the tabstops, include --tabsize along with the number of spaces

sdiff -t --tabsize 2 -w 185 fileone filetwo > filethree

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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