1

Lets say i have two files like below:

file1

a 23
b 34
c 47

file2
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.

0

2 Answers 2

5

Try:

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

3
1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .