How to compare the output of two commands?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

How to compare the output of two commands?

Sonixxfx
Hi,

I am using two large commands that both output a pretty large amount of text. I want to compare these two lists of text, but I do not want to redirect it to textfiles to be able to do that. I have tried to compare the output with diff, by using some bash functions, but I keep getting errors.
So does someone know of a way to compare the output?

To be more specific I want to compare a list like this, but much longer, to another list of text that has the same structure:

/usr
/usr/share
/usr/share/doc
/usr/share/doc/unzip
/usr/share/doc/unzip/copyright
/usr/share/doc/unzip/BUGS
/usr/share/doc/unzip/ToDo
/usr/share/doc/unzip/changelog.Debian.gz
/usr/share/doc/unzip/History.550.gz
/usr/share/doc/unzip/History.551.gz
/usr/share/doc/unzip/History.552.gz
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/funzip.1.gz
/usr/share/man/man1/unzip.1.gz
/usr/share/man/man1/unzipsfx.1.gz
/usr/share/man/man1/zipgrep.1.gz
/usr/share/man/man1/zipinfo.1.gz
/usr/bin
/usr/bin/unzip
/usr/bin/funzip
/usr/bin/unzipsfx
/usr/bin/zipgrep
/usr/bin/zipinfo

Thanks for your help.

Regards,

Ben

Reply | Threaded
Open this post in threaded view
|

Re: How to compare the output of two commands?

Alvin Oga

hi ya


On Mon, 17 Apr 2006, Sonixxfx wrote:

> To be more specific I want to compare a list like this, but much longer, to
> another list of text that has the same structure:
>
> /usr
> /usr/share
> /usr/share/doc
> /usr/share/doc/unzip
> /usr/share/doc/unzip/copyright
> /usr/share/doc/unzip/BUGS
> /usr/share/doc/unzip/ToDo
> /usr/share/doc/unzip/changelog.Debian.gz

PC-1# find /usr -print | sort > /tmp/list-1.txt

PC-2# find /usr -print | sort > /tmp/list-2.txt

        - use -type options to skip stuff
        - use grep -iv to skip stuff

copy the list-1.txt into PC2

diff /tmp/list-1.txt /tmp/list-2.txt

if you want to check for time stamps and permissions,
use --l  

        find /usr -print | xargs ls -la /usr --l

or solve the probelm one of hundred other ways

c ya
alvin


--
To UNSUBSCRIBE, email to [hidden email]
with a subject of "unsubscribe". Trouble? Contact [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: How to compare the output of two commands?

John O'Hagan
In reply to this post by Sonixxfx
On Mon, 17 Apr 2006 04:07 pm, Sonixxfx wrote:

[...]
>
> I am using two large commands that both output a pretty large amount of
> text. I want to compare these two lists of text, but I do not want to
> redirect it to textfiles to be able to do that.
[...]

Try

 comm <(command1) <(command2)

which will give you three columns of output: lines unique to command1, lines
unique to command2, and lines common to both. Options to comm are -1, -2
and -3, which suppress the respective column; e.g. comm -13 will only give
lines which are uniquely output from command2.

HTH,

John  


--
To UNSUBSCRIBE, email to [hidden email]
with a subject of "unsubscribe". Trouble? Contact [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: How to compare the output of two commands?

Alvin Oga


On Mon, 17 Apr 2006, John O'Hagan wrote:

>  comm <(command1) <(command2)

or kdiff x y

c ya
alvin


--
To UNSUBSCRIBE, email to [hidden email]
with a subject of "unsubscribe". Trouble? Contact [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: How to compare the output of two commands?

Sonixxfx
Thank you very much guys.

This command:

comm <(command1) <(command2)

is what I was looking for. I have tried this myself by using command substitution, but without succes. I now see I had to apply process substitution.

I am probably going to try out Linux From Scratch once. I like the power of all these command line tools, but it there is a lot to learn about them though. I think LFS will be a nice way to learn more about them (and Linux).

Regards,

Ben



2006/4/17, Alvin Oga <[hidden email]>:


On Mon, 17 Apr 2006, John O'Hagan wrote:

>  comm <(command1) <(command2)

or kdiff x y

c ya
alvin


--
To UNSUBSCRIBE, email to [hidden email]
with a subject of "unsubscribe". Trouble? Contact [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: How to compare the output of two commands?

linux4michelle
In reply to this post by Sonixxfx
Am 2006-04-17 08:07:16, schrieb Sonixxfx:
> Hi,
>
> I am using two large commands that both output a pretty large amount of
> text. I want to compare these two lists of text, but I do not want to
> redirect it to textfiles to be able to do that. I have tried to compare the
> output with diff, by using some bash functions, but I keep getting errors.
> So does someone know of a way to compare the output?

    diff `command opts` `command opts` |less

Greetings
    Michelle Konzack


--
Linux-User #280138 with the Linux Counter, http://counter.li.org/
##################### Debian GNU/Linux Consultant #####################
Michelle Konzack   Apt. 917                  ICQ #328449886
                   50, rue de Soultz         MSM LinuxMichi
0033/3/88452356    67100 Strasbourg/France   IRC #Debian (irc.icq.com)


--
To UNSUBSCRIBE, email to [hidden email]
with a subject of "unsubscribe". Trouble? Contact [hidden email]