{"id":249,"date":"2009-11-24T21:05:04","date_gmt":"2009-11-24T15:35:04","guid":{"rendered":"http:\/\/kedar.nitty-witty.com\/?p=249"},"modified":"2016-01-16T14:26:43","modified_gmt":"2016-01-16T14:26:43","slug":"usingvlookup-and-batch-script-to-compare-two-excel-csv-and-retrive-result","status":"publish","type":"post","link":"https:\/\/kedar.nitty-witty.com\/blog\/usingvlookup-and-batch-script-to-compare-two-excel-csv-and-retrive-result","title":{"rendered":"Using VLookup like Batch script to compare two excel \/ csv"},"content":{"rendered":"<p><strong>Using Vlookup:<\/strong><\/p>\n<p>I have two csv files; File1 has Id and Value Columns and File2 has Id.<\/p>\n<p>Problem: I need to compare both files and put respective values to File2 from File1.<\/p>\n<p>Solution: VLookup in excel<\/p>\n<p>Steps:<\/p>\n<ul>\n<li>Open both files in Excel &amp; arrange it vertically (Window &gt;&gt; Arrange; for ease)<\/li>\n<\/ul>\n<p style=\"text-align: center;\"><a href=\"http:\/\/kedar.nitty-witty.com\/wp-content\/uploads\/2009\/11\/vlookup-1.JPG\"><img decoding=\"async\" class=\"alignnone size-medium wp-image-250\" title=\"vlookup-1\" src=\"http:\/\/kedar.nitty-witty.com\/wp-content\/uploads\/2009\/11\/vlookup-1-299x199.jpg\" alt=\"vlookup-1\" width=\"299\" height=\"199\" \/><\/a><\/p>\n<ul>\n<li>Click on cell where you want to put compared value: B2<\/li>\n<li>Click on fx button and select VLOOKUP function.<\/li>\n<\/ul>\n<p style=\"text-align: center;\"><a href=\"http:\/\/kedar.nitty-witty.com\/wp-content\/uploads\/2009\/11\/vlookup-2.JPG\"><img decoding=\"async\" class=\"alignnone size-medium wp-image-251\" title=\"vlookup-2\" src=\"http:\/\/kedar.nitty-witty.com\/wp-content\/uploads\/2009\/11\/vlookup-2-300x201.jpg\" alt=\"vlookup-2\" width=\"300\" height=\"201\" \/><\/a><\/p>\n<ul>\n<li>Under lookup_value, click first search field: A2.<\/li>\n<li>Click back in Table_array text field, and click on button to select range. Select two column for comparison starting from second row, i.e. A2 to B9.<\/li>\n<li>Put 2 in Col_index_num. If lookup succeeds in finding lookup_value in Table_array it will return 2nd value as result.<\/li>\n<li>Put FALSE in Range_lookup to do exact match.<\/li>\n<li>Click ok, and you will find B2 will be filled with respective value.<\/li>\n<li>You may drag the command to other rows and values will get filled. Optionally you may copy and paste it from rows B3 to B9 to lookup and fill all values.<\/li>\n<\/ul>\n<p style=\"text-align: center;\"><a href=\"http:\/\/kedar.nitty-witty.com\/wp-content\/uploads\/2009\/11\/vlookup-3.JPG\"><img decoding=\"async\" class=\"aligncenter\" style=\"border: 0px initial initial;\" title=\"vlookup-3\" src=\"http:\/\/kedar.nitty-witty.com\/wp-content\/uploads\/2009\/11\/vlookup-3-300x212.jpg\" alt=\"vlookup-3\" width=\"300\" height=\"212\" \/><\/a><\/p>\n<ul>\n<li>You can observer in output here, if I change the value of ID in File2 which doesn\u2019t exist, VLookup returns #N\/A.<\/li>\n<\/ul>\n<p>Descriptions in details for this function and each respected field are easily available in excel help.<\/p>\n<p>Download Files: <a href=\"http:\/\/kedar.nitty-witty.com\/wp-content\/uploads\/2009\/11\/File1.csv\">File1<\/a>, <a href=\"http:\/\/kedar.nitty-witty.com\/wp-content\/uploads\/2009\/11\/File2.csv\">File2<\/a><\/p>\n<p><strong>Batch script to compare and assign value-simulate vlookup:<\/strong><\/p>\n<p>Further I came up with a batch script to compare field value, simulate vlookup.\u00a0After doinglittle testing, I managed to fix it.<\/p>\n<p><em>for \/f &#8220;tokens=1 delims=, skip=1&#8221; %%i in (File2.csv) do @findstr \u00a0&#8220;%%i,&#8221; File1.csv &gt;nul &amp; If errorlevel 0 if not errorlevel 1 (for \/f &#8220;tokens=1,2 delims=,&#8221; %%m in (&#8216;findstr \/i \/L &#8220;%%i,&#8221; File1.csv&#8217;) do (@echo %%m,%%n&gt;&gt;output.csv\u00a0echo %%i)) else (echo %%i,NA&gt;&gt;output.csv) <\/em><\/p>\n<p>Please consider this batch script is written specifically for these csv and prove my understanding.<br \/>\nThis script will compare file2 with file1, extract similar data from file1 and put it in output.csv.<\/p>\n<p><strong>Download batch file: <a href=\"http:\/\/kedar.nitty-witty.com\/wp-content\/uploads\/2009\/11\/vlukup.bat\">vlookup-batch.bat<\/a><br \/>\n<\/strong><\/p>\n<p>If you find any difficulty or don&#8217;t yield required results by following above process or using script, comment.<\/p>\n","protected":false},"excerpt":{"rendered":"Using Vlookup: I have two csv files; File1 has Id and Value Columns and File2 has Id. Problem: I need to compare both files and put respective values to File2&hellip;\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[6],"tags":[18,290,24,288,291,426,292,289,125],"class_list":{"0":"post-249","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-technical","7":"tag-batch","8":"tag-batch-script","9":"tag-code","10":"tag-compare-csv","11":"tag-csv-compare","12":"tag-technical","13":"tag-using-vlookup","14":"tag-vlookup","15":"tag-windows"},"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/249","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/comments?post=249"}],"version-history":[{"count":5,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/249\/revisions"}],"predecessor-version":[{"id":1683,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/posts\/249\/revisions\/1683"}],"wp:attachment":[{"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/media?parent=249"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/categories?post=249"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kedar.nitty-witty.com\/blog\/wp-json\/wp\/v2\/tags?post=249"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}