Given 3 files, each with names of thousands of customers who bought something from Amazon.com on that particular day. Find the common customers (i.e. common names in file1 and file2 and file3)
Solution:
1) assuming UNIX like systems:
cat f1 f2 | sort | uniq -d > tmpfile;
cat f3 tmpfile | sort | uniq -d
-------------------
Better options:
sort f1 f2 f3 |uniq -d
http://www.softpanorama.org/Tools/Sort/unix_sort_examples_collection.shtml
sort -t ':' -k 3,4 /etc/passwd
http://amazoninterview.blogspot.com/2007/05/find-common-data-from-three-files.html
No comments:
Post a Comment