开发者

problem with output of side difference using sdiff in unix

I am using the following sdiff command to get the side-by-side difference of two files. Column width is given as one of the options

sdiff -w170 /tmp/captureFile /tmp/referenceFile (or diff -y )

if i use -w 130 then some characters are stripped. They do not appear in output even on next line. They are lost.

And if -w 170 is used then due to extra characters in the left column, right column is shifted and so few of its characters are seen in the left column part due to screen width being smaller.

So is there any option not to strip off the character开发者_如何学Cs and have then on the next line in the same column of the sdiff command output?


What you are seeing (obviously) is either line truncation (-w 130) or line wrap (-w 170) relative to the line length in your terminal session. I don't believe there is an option to do what you desire. I've used sdiff a lot & tend to use a terminal/CLI that supports changing font sizes.

Shrink the font to something still readable & then maximise the window if possible.

Something else I've done is to 'fold' the two files before comparison to have a shorter line length - depends if you're on Linux or some Unix distro. but fold should be there.


Here is a quick and dirty script I wrote to implement @David Victor's suggestion :

$ cat SDIFF
if [ ! -n "${COLUMNS}" ]
then
        echo COLUMNS is not exported !!!
        echo run :
        echo export COLUMNS
        exit 1
fi

if [ ! -f "$1" -o ! -f "$2" ]
then
        echo usage: $0 file1 file2
        exit 1
fi

H=$(((${COLUMNS} - 3) / 2))

F1=$(mktemp)
F2=$(mktemp)
trap "rm $F1 $F2" 0

fold -s -w $H $1 > $F1
fold -s -w $H $2 > $F2

sdiff -w ${COLUMNS} $F1 $F2 | less
$
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜