pattern search between 2 files

Afternoon guys,

I have 2 files, 1.txt and 2.txt containing employee numbers.
the 1st file (1.txt) is an extract from sybase with active employee numbers, the 2nd (2.txt) is a scan from the sybase log containing successfull logins *** which i have already mined and now contains only employee numbers as well***

I need to find employee numbers that are active but have not logged in, thus i am looking for values withing 1.txt that are not in 2.txt and output this to 3.txt.

I have tried "diff", "comm", awk and a for loop below without success.

#! /bin/sh
awk '
FILENAME=="2.txt" { arr[$0]++}
FILENAME=="1.txt" { if (arr[$0]==0) {print $0} }'
2.txt 1.txt 3.txt

for x in 'cat 1.txt'; do
grep $x 2.txt > test.txt ;
done

Hopefully you guys could please help me out.

Try this:

awk 'NR==FNR{a[$0];next}!($0 in a)' 2.txt 1.txt > 3.txt

Regards

awk: syntax error near line 1
awk: bailing out near line 1

Use nawk or /usr/xpg4/bin/awk on Solaris.

If you have GNU AWK and you're missing the above error, try:

gawk --nostalgia

:slight_smile:

Cool stuff, Thank you guys, much appreciated!

> cat file95
101
102
103
104
105
106
107
108
109
110
> cat file96
101
105
106
107
109

This command will give the entries unique to file95

> comm -23 file95 file96
102
103
104
108
110