0

The version of diff in my cygwin has a number of advanced options which allow me to print out one difference per line.

Given two files one.txt and two.txt.

one.txt:

one
two
three
four
five
six

two.txt

one
two2
three
four
five5
six

And running diff in cygwin with the following options/parameters:

diff -y --suppress-common-lines one.txt two.txt

Gives an output of:

two   |two2
five  |five5

This is the type of format I'm after whereby one difference is printed out per line. On my dev solaris box, the "-y" option is not supported, so I'm stuck with an output which looks like this:

2c2
< two
---
> two2
5c5
< five
---
> five5

Does anyone know of a way I can get an output of one difference per line on this solaris box? Maybe using a sed/awk one liner to massage the output from this more primitive diff output? (Please note, I am not able to install a more up-to-date diff version on this solaris box).

Thanks!

5 Answers 5

2

Use GNU diff.

http://www.gnu.org/software/diffutils/

You can build and install it into your local directory, no? If you have a home directory and a compiler and a make, you can build your own GNU diff.

I don't have Solaris, but I can't imagine it would be much more than this:

./configure --prefix=/home/bob
make
make install

No root privileges required.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Andy, sounds good. I don't have make available on the solaris box but I've passed it over to my sysadmin to build for me. Will see how it goes.
The Solaris box has NO development tools on it? That's hard to imagine. Are you sure you know where it should be? Have you looked in /usr/ucb for make and cc?
/usr/ucb and /usr/sfw mostly have the tools on a full Solaris 10 install... (gmake instead of make, etc though...)
1

comm -3 almost does what you want, but requires sorted input. It also will put them in separate lines by alphabetical order. Your example (once sorted) would show up as

five
      five5
two
      two2

If solaris diff won't do what you want, then nothing on a standard solaris box is liable to do so either, which means introducing code from elsewhere, either your own or someone else's. As GNU diff does what you want, just use that.

Comments

1

Example output:

# ~/config_diff.sh postfix_DIST/master.cf postfix/master.cf
postfix_DIST/master.cf: -o smtpd_tls_security_level=encrypt -o smtpd_sasl_auth_enable=yes -o smtpd_client_restrictions=permit_sasl_authenticated,reject -o smtpd_tls_wrappermode=yes -o smtp_fallback_relay=
postfix/master.cf: -o cleanup_service_name=cleanup_sasl -o smtpd_tls_security_level=encrypt -o smtpd_sasl_auth_enable=yes -o smtpd_client_restrictions=permit_sasl_authenticated,reject -o cleanup_service_name=cleanup_sasl -o smtpd_tls_wrappermode=yes -o smtpd_sasl_auth_enable=yes -o smtpd_client_restrictions=permit_sasl_authenticated,reject -o smtp_fallback_relay=

postfix_DIST/master.cf:smtp inet n - - - - smtpd smtp unix - - - - - smtp
postfix/master.cf:smtp inet n - - - - smtpd smtp unix - - - - - smtp

Sadly, it cannot currently handle several same configurations variables ... it counts them and will think the the files differ.

1 Comment

I made it work with double configurations lines ... by "cksum"
1

All the answers given above and below are perfect but just typing a command and getting a result wont help you in solving similar problems in future.

Here a link which explains how diff works. once you go through the link, you can the problem yourself

Here is a link. https://www.youtube.com/watch?v=5_dyVrvbWjc

Comments

0
#! /bin/bash

FILES="$@"

COLUMN=1

for variable in $( awk -F: '{print $X}' X=${COLUMN} ${FILES} | sort -u ) ; do
        NUM_CONFIGS=$( for file in ${FILES} ; do
                grep "^${variable}" ${file}
        done | sort -u | wc -l )
        if [ "${NUM_CONFIGS}" -ne 1 ] ; then
                for file in ${FILES} ; do
                        echo ${file}:$( grep "^${variable}" ${file} )
                done
                echo
        fi
done

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.