Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Lets say i have two files like below:


a 23
b 34
c 47

a justin_beiber_sucks
b segmentation fault
c jackson
d nop

Now what i want is to get a diff of the first column of two file. I'm doing it now like

$cat file1 awk '{print $1}'> f1
$cat file2 awk '{print $1}'> f2
$diff -u f1 f2

But this approach feels retarded. Any tricky approach there?

Problem is i always view pipes as one dimensional thing, but here its two dimensional. I mean the input to diff has to come from two different sources simultaneously.

starting point may be the awk script will read both files, do filtering and save the result in a temporary associative array, next it will invoke diff and will supply its inputs.

share|improve this question
up vote 4 down vote accepted


diff -u <(awk '{print $1}' file-one) <(awk '{print $1}' file-two)

share|improve this answer
@DennisWilliamson, I wish I could edit comments. I am going to deleted it and re-create. – Zoredache Jul 26 '12 at 1:18
Also known as Process substitution. – Zoredache Jul 26 '12 at 1:19
linking this page will be more appropriate – Aftnix Jul 26 '12 at 9:40

Chances are good that join will do what you want:

join <(sort file1) <(sort file2)

But since you don't say what you are really trying to accomplish, it's difficult to determine what options might be appropriate.

share|improve this answer

Your Answer


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.