Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have these two files:-

[root@localhost base_filters]# cat aix_old
joe
amadeus
image
bill
juliet
charlie
romeo
ftp


[root@localhost base_filters]# cut -d: -f1 passwd2
henry
amadeus
image
bill
julie
jennifer
charlie
romeo
harry

I am trying to find out the differences between two files; so I am using the following command:-

[root@localhost base_filters]# cut -d: -f1 passwd2 | sort | diff `sort aix_old` -

But getting this following error:

diff: extra operand `charlie'
diff: Try `diff --help' for more information.

I know I can use another temporary file for sorting the contents in aix_old but I don't want another temporary file; so tried with command substitution.

Any idea, what I might be doing wrong.

share|improve this question

1 Answer 1

up vote 8 down vote accepted
diff <(cut -d: -f1 passwd2 | sort) <(sort aix_old)

gives:

4,5c4
< harry
< henry
---
> ftp
7,8c6,7
< jennifer
< julie
---
> joe
> juliet
diff -y <(cut -d: -f1 passwd2 | sort) <(sort aix_old)

gives:

amadeus                              amadeus
bill                                bill
charlie                             charlie
harry                                 | ftp
henry                                 <
image                               image
jennifer                              | joe
julie                                 | juliet
romeo                               romeo

From the process substition wiki: http://en.wikipedia.org/wiki/Process_substitution

The Unix diff command normally accepts the names of two files to compare, or one file name and standard input. Process substitution allows you to compare the output of two programs directly:

$ diff <(sort file1) <(sort file2)

The <(command) expression tells the command interpreter to run command and make its output appear as a file. The command can be any arbitrarily complex shell command.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.