Process diff command output in a shell script

diff -yta file1 file2
#!/usr/abc/b/bin/perl5.6                                    |  #!/usr/abc/b/bin/perl5.8

Notable thing about above line is "|" appears at 62nd position. When the same line is assigned in a variable in a ksh script, using

ss=$(diff -yta file1 file2)

it appears as

#!/usr/abc/b/bin/perl5.6 | #!/usr/abc/b/bin/perl5.8

As you may notice, all the spaces are removed. What I want to do is process the exact output of diff command line by line.

Appreciate any pointers on this.

Thanks in advance.

The "problem" is the way parameter expansion is done. Example:

$ cat test.sh
#!/usr/bin/ksh

VAR='Test  with  double  size  whitespace  !'

echo $VAR
echo "$VAR"
$ ksh test.sh
Test with double size whitespace !
Test  with  double  size  whitespace  !

Spot the difference? In the first example, echo is passed 6 parameters (split on the whitespaces), and by default it outputs them using one whitespace as separator. In the second example, the variable is passed as one parameter, whitespaces and all.

Fantastic! Thanks pludi.

The other question I have is how can I show entire line content in the diff result? I tried with diff -yta -W 300, however, the result is distorted.

Any idea?

Thanks.

What do you mean by "distorted"? Can you give an example?

diff -yta -W 300 file1 file2

#!/usr/abc/b/bin/perl5.6                                                                                                                         |  #!/usr/abc/b/bin/perl5.8
###########################################################################                                                                             ###########################################################################

Above result shows output from file1 followed by file2. As you may notice, diff tries to set the result in 300 characters and that's why the output doesn't set on one line.

Does it help to understand the scenario?