Tech Tip: Intersection of Two Files
I was working on trying to figure out whether to retweet @graywolf‘s post about his new business centered around viral marketing. My thought was that certainly anyone that was following me on twitter would be following him. In order to find out, I wrote a quick shell script to pull down his followers using the twitter api and pulled it into a flat file and grep’d out the users from all the other data.
How do You Find the Intersection of the Files?
To fiind the intersection of the resulting files, I found a simple way to do it on the command-line.
grep -f file1 file2
Done. That’s easy, no?
This takes each line of file1 and uses it as a pattern to match in file2. Grep is a command line application found natively on all linux distributions and mac os’s. You can use it on windows xp or vista by installing cygwin.
Comments Off
