Monday, October 27, 2008

Extracting Similarity Between Two (Text) Files

When you need to compare difference between two files, you have diff.
When you need to find similarity between such files, as far as I know, you need to devise your own script.
This is my oneliner script for such need (assuming files to be compared named file-01 & file-02):

for ((i=1;i<=$(wc -l file-01|awk '{print $1}');i+=1)); do grep $(awk -v a=$i 'NR==a' file-01) file-02 ; done

Ugly, but working...

No comments: