top11,facebook.com2,google.com3,youtube.com4,yahoo.com5,wikipedia.org6,baidu.com7,live.com8,amazon.com9,qq.com10,twitter.comtop21,facebook.com2,google.com3,youtube.com4,yahoo.com5,baidu.com6,wikipedia.org7,live.com8,qq.com9,amazon.com10,twitter.comdiff -u  /Users/stofke/Desktop/top2a.csv /Users/stofke/Desktop/top1a.csv |  sed -n '1,2d;/^[-+]/p' |  sort --field-separator=',' --key=2 +9,amazon.com-8,amazon.com+5,baidu.com-6,baidu.com+8,qq.com-9,qq.com+6,wikipedia.org-5,wikipedia.orgBut I actually need this: +1, amazon.com -1  baidu.com -1  qq.com +1  wikipedia.orgI don't know how to do that last step(I would also need to calculate the % wise decline or raise)Adding |  paste -d, - -gets me this+9,amazon.com,-8,amazon.com+5,baidu.com,-6,baidu.com+8,qq.com,-9,qq.com+6,wikipedia.org,-5,wikipedia.org
How can I show the number of positions lines have moved in diff output?
bash;diff;csv
You could also consider an approach using join since you want sorted output in the end. Like:join -t, -j2 <(sort -t, -k2 file1) <(sort -t, -k2 file2) |   awk -F, '{n=$3-$2; if (n) print n, $1}'