{"id":187,"date":"2010-06-02T15:00:50","date_gmt":"2010-06-02T14:00:50","guid":{"rendered":"http:\/\/www.nax.cz\/2010\/06\/02\/compare-2-lists-in-bash\/"},"modified":"2010-06-02T15:00:50","modified_gmt":"2010-06-02T14:00:50","slug":"compare-2-lists-in-bash","status":"publish","type":"post","link":"https:\/\/nax.cz\/?p=187","title":{"rendered":"compare 2 lists in bash"},"content":{"rendered":"<p>Interesting task &#8211; compare 2 lists (in my case hostnames). You can use diff, but need to sort | unique them first. Rather I wrote a very simple script to do it:<\/p>\n<pre>\n#!\/bin\/bash\nFILE1=$1\nFILE2=$2\n\ncat $FILE1 | \\\nwhile read ITEM ; \ndo \n\tgrep -i \"^$ITEM$\" $FILE2 &> \/dev\/null\n\techo $ITEM,$?\ndone | \\\ngrep '1$' | \\\ncut -f1 -d,\n<\/pre>\n<p>And second very simple script to convert for SQL WHERE HOST_NAME IN () notation:<\/p>\n<pre>\n#!\/bin\/bash\n\nwhile read ITEM\ndo\n\techo -n \\'$ITEM\\',\ndone\n<\/pre>\n<p>Nice exercises for bash while construct, isn&#8217;t it?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Interesting task &#8211; compare 2 lists (in my case hostnames). You can use diff, but need to sort | unique them first. Rather I wrote a very simple script to do it: #!\/bin\/bash FILE1=$1 FILE2=$2 cat $FILE1 | \\ while read ITEM ; do grep -i &#8222;^$ITEM$&#8220; $FILE2 &#038;> \/dev\/null echo $ITEM,$? done | \\ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[42],"tags":[48,75,78,83],"class_list":["post-187","post","type-post","status-publish","format-standard","hentry","category-bash-scripting-unix-sw-computers-unix-sw-computers","tag-bash","tag-script","tag-sql","tag-while"],"_links":{"self":[{"href":"https:\/\/nax.cz\/index.php?rest_route=\/wp\/v2\/posts\/187","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nax.cz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nax.cz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nax.cz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nax.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=187"}],"version-history":[{"count":0,"href":"https:\/\/nax.cz\/index.php?rest_route=\/wp\/v2\/posts\/187\/revisions"}],"wp:attachment":[{"href":"https:\/\/nax.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=187"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nax.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=187"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nax.cz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=187"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}