{"id":470,"date":"2014-02-04T14:19:16","date_gmt":"2014-02-04T19:19:16","guid":{"rendered":"http:\/\/devolve.net\/blog\/?p=470"},"modified":"2015-05-21T10:09:21","modified_gmt":"2015-05-21T14:09:21","slug":"join-the-command","status":"publish","type":"post","link":"https:\/\/www.devolve.local\/join-the-command\/","title":{"rendered":"join: the command"},"content":{"rendered":"

From the manual:<\/p>\n

NAME\r\n     join -- relational database operator\r\n\r\nSYNOPSIS\r\n     join [-a file_number | -v file_number] [-e string] [-o list] [-t char]\r\n          [-1 field] [-2 field] file1 file2<\/pre>\n

I had two CSVs, baz01.csv<\/code> and baz02.csv<\/code>. They shared the same first column, which was a list of database table names. The second column contained the number of rows from each table. The row numbers between the two files were different, and I wanted to compare them. The join<\/code> command to the rescue!<\/p>\n

join -t , -1 1 -2 1 baz01.csv baz02.csv \\\r\n  | awk -F, '{print $1\",\"$2\",\"$3\", \"($3 - $2)}'<\/pre>\n

gave me exactly what I wanted: the output contains the first identical column from both files, followed by column 2 of the baz01.csv<\/code>, followed by the second column of baz02.csv<\/code>, followed by the third column minus the second.<\/p>\n

Of course, this will only work on the simplest CSV files, meaning no escaped or quoted commas allowed.<\/p>\n","protected":false},"excerpt":{"rendered":"

From the manual: NAME join — relational database operator SYNOPSIS join [-a file_number | -v file_number] [-e string] [-o list] [-t char] [-1 field] [-2 field] file1 file2 I had two CSVs, baz01.csv and baz02.csv. They shared the same first column, which was a list of database table names. The second column contained the number […]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[34,41],"_links":{"self":[{"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/posts\/470"}],"collection":[{"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/comments?post=470"}],"version-history":[{"count":4,"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/posts\/470\/revisions"}],"predecessor-version":[{"id":474,"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/posts\/470\/revisions\/474"}],"wp:attachment":[{"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/media?parent=470"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/categories?post=470"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devolve.local\/wp-json\/wp\/v2\/tags?post=470"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}