0

I have two texts. One like this:

house structure
bank economy
rose animal
...

And another text which contains more than one "label "of each word:

house structure
bank economy
bank confort
rose plant
...

What I need is to count if the second field of the first text is the same of ONE OF THE MANY of the second text's second field. For example, the word "house" its a structure in the first and also in the second, so +1. The word "bank" of the first text is economy, and it is also ONE OF THE MANY in the second text, so +1 also. The word "rose" it is labelled as animal in the first and not in the second, so +0.

In the end I need a number of points. What is the easiest way to do so? Thanks for the help, it is a little messy.

1

It's not a linux answer, but for this sort of thing I'd port both files into excel and then use vlookup and/or count to compare them.

1

Based on your example, it seems like you want to find whether or not a given line from the first file is present in the second file. If that is the case, you can do

grep -c -f file1 file2

In this context, also look at this and this post if speed is an issue.

1

How about

awk 'NR==FNR {a[$1]=$2; next;} a[$1]==$2' text1 text2
house structure
bank economy

or if you want an actual count

awk 'NR==FNR {a[$1]=$2; next;} a[$1]==$2 {c[$1]++} END {for (i in c) print i, c[i]}' text1 text2
house 1
bank 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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