{"id":8256,"date":"2021-11-28T02:18:52","date_gmt":"2021-11-28T02:18:52","guid":{"rendered":"https:\/\/lgildv5i97.onrocket.site\/answers\/?post_type=question&#038;p=8256"},"modified":"2021-11-28T02:19:55","modified_gmt":"2021-11-28T02:19:55","slug":"solved-batch-script-to-split-a-text-file-into-multiple-files","status":"publish","type":"question","link":"https:\/\/computing.net\/answers\/programming\/batch-script-to-split-a-text-file-into-multiple-files\/29175.html","title":{"rendered":"Solved Batch Script To Split a Text File Into Multiple Files"},"content":{"rendered":"<p>Please find below my code to split the file :<\/p>\n<p>@Echo off<\/p>\n<p>SETLOCAL ENABLEEXTENSIONS<br \/>\nSETLOCAL ENABLEDELAYEDEXPANSION<\/p>\n<p>Set \/a xxFileNo=1<br \/>\nSet \/a xxRecLimit=25<br \/>\nSet \/a xxRecCount=0<br \/>\nSet \/a cnt=0<\/p>\n<p>Set &#8220;xxOutFile=D:\\MyTextFileName_!xxFileNo!.txt&#8221;<br \/>\nSet &#8220;xxInFile=D:\\MyTextFileName.txt&#8221;<\/p>\n<p>for \/f &#8220;tokens=* delims=^|&#8221; %%1 in (!xxInFile!) Do (<\/p>\n<p>Echo %%1&gt;&gt;!xxOutFile!<br \/>\nSet \/a xxRecCount+=1<br \/>\nset \/a cnt+=1<\/p>\n<p>if !cnt! gtr !xxRecLimit! (<br \/>\nSet \/a xxFileNo+=1<br \/>\nSet &#8220;xxOutFile=D:\\MyTextFileName_!xxFileNo!.txt&#8221;<\/p>\n<p>Set &#8220;Header=&#8221;MyCustom Header Line&#8221;<br \/>\nEcho !Header!&gt;&gt;!xxOutFile!<br \/>\nSet \/a xxRecCount-=1<br \/>\nSet \/a cnt=1<br \/>\n)<br \/>\n)<\/p>\n<p>This code misses few records while writing to the output file. For example i have 100 records, each file should have 25 records in them. But this code only writes 17 record lines to the fourth file.<\/p>\n<p>Can anyone help me in this code. It is little urgent and your help is much appreciated.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"iawp_total_views":20},"question-category":[55],"question_tags":[],"class_list":["post-8256","question","type-question","status-publish","hentry","question-category-programming"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question\/8256","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question"}],"about":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/types\/question"}],"author":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/comments?post=8256"}],"wp:attachment":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/media?parent=8256"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question-category?post=8256"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question_tags?post=8256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}