output comparison

output comparison

Post by Faeanda » Sun, 06 Jun 2004 04:34:56



I want to compare the output of 2 commands and report on what is
different between the two.  Redirecting both to a file and diff'ing
won't work as the first thing missing in one output could be the
second line, in which case the whole damn file is different.

I need to be able to report on what is missing from output2, and only
what is missing.  The specific example is this:

First output:
sudo rsh filer1 qtree | cut -f2 | sort

This will give me a list of names

Second output:
sudo rsh filer2 snapmirror status | cut -d/ -f4 | sort

This will also give me a list of names.

In this example I want to see what is missing from output 2, all in
one fluid script.  I'm sure it's possible but I can't find how.  Any
pointers?

Thanks.

~F

 
 
 

output comparison

Post by Ed Morto » Sun, 06 Jun 2004 04:52:39



> I want to compare the output of 2 commands and report on what is
> different between the two.  Redirecting both to a file and diff'ing
> won't work as the first thing missing in one output could be the
> second line, in which case the whole damn file is different.

Diff won't report the whole file being different in this case. You could
also use "comm".

Quote:> I need to be able to report on what is missing from output2, and only
> what is missing.  The specific example is this:

> First output:
> sudo rsh filer1 qtree | cut -f2 | sort

> This will give me a list of names

> Second output:
> sudo rsh filer2 snapmirror status | cut -d/ -f4 | sort

> This will also give me a list of names.

In both of the above, you may want to use "sort -u" to remove duplicates.

Quote:> In this example I want to see what is missing from output 2, all in
> one fluid script.  I'm sure it's possible but I can't find how.  Any
> pointers?

If you don't mind 2 temp files, use "comm".

If you do mind 2 temp files, you could do something like this (untested):

(sudo rsh filer1 qtree | cut -f2 | sort -u; echo "SEPARATOR"; sudo rsh
filer2 snapmirror status | cut -d/ -f4 | sort -u) |
awk 'sawSep == 1 { if (! $0 in names) print; next }
        /SEPARATOR/ { sawSep = 1; next }
        { names[$0] = "" }'

Regards,

        Ed.

Quote:> Thanks.

> ~F


 
 
 

output comparison

Post by Ed Morto » Sun, 06 Jun 2004 04:56:18


<snip>

Quote:> (sudo rsh filer1 qtree | cut -f2 | sort -u; echo "SEPARATOR"; sudo rsh
> filer2 snapmirror status | cut -d/ -f4 | sort -u) |
> awk 'sawSep == 1 { if (! $0 in names) print; next }
>     /SEPARATOR/ { sawSep = 1; next }
>     { names[$0] = "" }'

I think I misread which missing names you wanted (the above prints names
from the 2nd command that weren't in the output of the 1st one), so you
may want to flip the order of the sudo... commands but hopefully you get
the idea.

        Ed.

 
 
 

output comparison

Post by John W. Krah » Sun, 06 Jun 2004 13:53:02



> I want to compare the output of 2 commands and report on what is
> different between the two.  Redirecting both to a file and diff'ing
> won't work as the first thing missing in one output could be the
> second line, in which case the whole damn file is different.

> I need to be able to report on what is missing from output2, and only
> what is missing.  The specific example is this:

> First output:
> sudo rsh filer1 qtree | cut -f2 | sort

> This will give me a list of names

> Second output:
> sudo rsh filer2 snapmirror status | cut -d/ -f4 | sort

> This will also give me a list of names.

> In this example I want to see what is missing from output 2, all in
> one fluid script.  I'm sure it's possible but I can't find how.  Any
> pointers?

You could do it in Perl:

#!/usr/bin/perl

for ( map { (split /\//)[3] } `sudo rsh filer2 snapmirror status` ) {
    unless ( exists $first{ $_ } ) {
        print "$_ is missing.\n";
        }
    }

John
--
use Perl;
program
fulfillment

 
 
 

1. output comparison from 2 files

Hi.  I'm just beginning with shell programming.  The situation is as
follows:  I have a program that controls that our systems are on-line
(via ping).  The output is written to a file.  Now we want to modify the
script so that is the system goes off-line that we don't continually get
messages (every hour from the crontab) that the system still is
off-line, but once when it goes off-line and once again when the system
is on-line again.

So, I was thinking if I have a out file named current and  another
called history and a comparison was made between the contents of the two
files and depending if the system is offline or on-line.  This is
unfortunately a little ahead of my current knowledge.  I know how to do
basic do/done loops and if statements but this is a little too advance
for me.

I would very much appreciate it if someone could point me in the right
direction with some tips.

thanks in advance for your help!

Sandy.

2. Incrementing a character value in csh?

3. stty -g output mapping to stty -a output

4. Urgent question, could be awk...help!

5. Repost of "Output redirection while reformatting the output"

6. HOWTO umaks()

7. Perl script log file output has duplicate copies of output lines

8. mod_rewrite question

9. Outputting to a log file and translating output

10. 4.3.2 Man command outputs 81 column output?

11. Verbose output vs. discarding output

12. How to make CC output like cc output?

13. meaning of stack size difference for pmap output and pmap -r output