{"id":4059,"date":"2021-11-08T11:42:39","date_gmt":"2021-11-08T11:42:39","guid":{"rendered":"https:\/\/lgildv5i97.onrocket.site\/answers\/?post_type=question&#038;p=4059"},"modified":"2021-11-08T11:43:23","modified_gmt":"2021-11-08T11:43:23","slug":"solved-batch-file-to-copy-specific-lines-of-text","status":"publish","type":"question","link":"https:\/\/computing.net\/answers\/programming\/batch-file-to-copy-specific-lines-of-text\/28785.html","title":{"rendered":"Solved Batch File To Copy Specific Lines of Text"},"content":{"rendered":"<p>Hello, I&#8217;m trying to create a text file by outputting lines from existing text files using Windows&#8217; Command Prompt\/Batch files. I&#8217;m using the FOR \/F command with the &#8220;SKIP=x&#8221; to find and copy specific lines from a text file. The output is starting with the first SKIP= number, but it doesn&#8217;t stop until it&#8217;s finished echoing the entire file. I need it to ECHO one line, stop, find the next line, ECHO new line, stop, etc&#8230; until all 7 lines are copied to the new file. Then, it should insert a space (ECHO.) and start the next file.<\/p>\n<p>Here&#8217;s what I&#8217;ve got:<\/p>\n<p>for %%i in (&#8220;*.doc&#8221;) do (<br \/>\necho %%i &gt;&gt; lines.txt<br \/>\nfor \/f &#8220;skip=493 tokens=1 delims=&#8221; %%a in (%%i) do echo %%a &gt;&gt; lines.txt<br \/>\nfor \/f &#8220;skip=7 tokens=1 delims=&#8221; %%a in (%%i) do echo %%a &gt;&gt; lines.txt<br \/>\nfor \/f &#8220;skip=9 tokens=1 delims=&#8221; %%a in (%%i) do echo %%a &gt;&gt; lines.txt<br \/>\nfor \/f &#8220;skip=567 tokens=1 delims=&#8221; %%a in (%%i) do echo %%a &gt;&gt; lines.txt<br \/>\nfor \/f &#8220;skip=588 tokens=1 delims=&#8221; %%a in (%%i) do echo %%a &gt;&gt; lines.txt<br \/>\nfor \/f &#8220;skip=589 tokens=1 delims=&#8221; %%a in (%%i) do echo %%a &gt;&gt; lines.txt<br \/>\nfor \/f &#8220;skip=590 tokens=1 delims=&#8221; %%a in (%%i) do echo %%a &gt;&gt; lines.txt<br \/>\necho. &gt;&gt; lines.txt<\/p>\n<p>The first ECHO line is to output the original filename (for future reference), then I&#8217;m using the FOR \/F lines to locate lines by number (not content), and copy just that line into the Lines.txt file.<\/p>\n<p>The input data looks something like this:<\/p>\n<p>&lt;data&gt;<br \/>\n&lt;heading&gt;<br \/>\n&lt;title&gt;<br \/>\nTitle<br \/>\nName<br \/>\ninformation<br \/>\ndate<br \/>\ndata<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"iawp_total_views":81},"question-category":[55],"question_tags":[],"class_list":["post-4059","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\/4059","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=4059"}],"wp:attachment":[{"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/media?parent=4059"}],"wp:term":[{"taxonomy":"question-category","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question-category?post=4059"},{"taxonomy":"question_tags","embeddable":true,"href":"https:\/\/computing.net\/answers\/wp-json\/wp\/v2\/question_tags?post=4059"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}