How can find the intersection between files
for Example:
file1
entry1
entry2
entry3
entry33
file2
entry2
entry4
entry5
.
.
.
.
the output should be
entry2
Thanks in advanced
How can find the intersection between files
for Example:
file1
entry1
entry2
entry3
entry33
file2
entry2
entry4
entry5
.
.
.
.
the output should be
entry2
Thanks in advanced
Hi,
You can get the expected output using for loop as follows.
for i in `cat file1 | awk {'print $1'}`
do
grep ${i} file2
done
Thanks,
Aketi...
With awk:
awk 'NR==FNR{a[$0]=$0;next}a[$0]' file1 file2
Regards
its give me nothing
its give me this error
awk: syntax error near line 1
awk: bailing out near line 1
regards,
Ismail
Use nawk or /usr/xpg4/bin/awk on Solaris.
grep -f file1 file2
hope this one helps for you
awk '{ chk_str="grep ^"$0"$ ./file2_name" ; system(chk_str) }' file1_name
Hi.
The command comm finds simple differences and the intersection between the contents of two sorted files. Here is the latter:
% comm -12 file1 file2
Producing:
entry2
See the man page for details ... cheers, drl
It is working fine for me.