{"id":432,"date":"2019-07-26T17:19:49","date_gmt":"2019-07-27T00:19:49","guid":{"rendered":"http:\/\/gantovnik.com\/bio-tips\/?p=432"},"modified":"2021-11-12T13:29:06","modified_gmt":"2021-11-12T21:29:06","slug":"windows-batch-script-to-print-nth-lines-after-line-containing-matched-string","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2019\/07\/windows-batch-script-to-print-nth-lines-after-line-containing-matched-string\/","title":{"rendered":"#63 Batch script to print n-th lines after line containing matched string"},"content":{"rendered":"<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n@echo off\r\nsetlocal enableDelayedExpansion\r\n\r\nset &quot;word=VON MISES&quot;\r\nset &quot;keep=3&quot;\r\nset &quot;file=model.f06&quot;\r\n\r\nfind  &quot;   X   &quot; model.f06  &gt; extract_weight.txt\r\n\r\ndel extract_stress.txt\r\n\r\nset n=%keep%\r\nfor \/f &quot;usebackq delims=&quot; %%A in (&quot;%file%&quot;) do (\r\n  set &quot;ln=%%A&quot;\r\n  if &quot;!ln:%word%=!&quot; neq &quot;!ln!&quot; (\r\n    echo(\r\n    set n=0\r\n  )\r\n  if !n! lss !keep! (\r\n    echo !ln! &gt;&gt; extract_stress.txt\r\n    set \/a n=n+1\r\n  )\r\n)\r\n\r\nREM pause &gt; nul\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>@echo off setlocal enableDelayedExpansion set &quot;word=VON MISES&quot; set &quot;keep=3&quot; set &quot;file=model.f06&quot; find &quot; X &quot; model.f06 &gt; extract_weight.txt del extract_stress.txt set n=%keep% for \/f &quot;usebackq delims=&quot; %%A in (&quot;%file%&quot;) do ( set &quot;ln=%%A&quot; if &quot;!ln:%word%=!&quot; neq &quot;!ln!&quot; ( echo( set n=0 ) if !n! lss !keep! ( echo !ln! &gt;&gt; extract_stress.txt set \/a n=n+1 ) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","_lmt_disableupdate":"yes","_lmt_disable":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[17],"tags":[],"class_list":["post-432","post","type-post","status-publish","format-standard","hentry","category-batch"],"modified_by":"gantovnik","jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8bH0k-6Y","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":907,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/05\/164-batch-script-to-create-md5-hash-for-every-file-in-the-folder-then-write-them-to-the-text-file\/","url_meta":{"origin":432,"position":0},"title":"#164 Batch script to create md5 hash for every file in the folder, then write them to the text file","author":"gantovnik","date":"2021-05-05","format":false,"excerpt":"#164 Batch script to create md5 hash for every file in the folder, then write them in text file [code language=\"python\"] @echo off FOR \/F \"delims=\" %%F IN ('dir \/B \/A \/S *') DO ( for %%D in (\"%%~dpF\\.\") do ( set filename=%%~nxD.md5 ) ) TYPE NUL > %filename% For\u2026","rel":"","context":"In &quot;batch&quot;","block_context":{"text":"batch","link":"https:\/\/gantovnik.com\/bio-tips\/category\/batch\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":688,"url":"https:\/\/gantovnik.com\/bio-tips\/2020\/09\/121-windows-batch-script-to-run-every-nastran-input-file-in-folder\/","url_meta":{"origin":432,"position":1},"title":"#121: Windows batch script to run every Nastran input file in folder","author":"gantovnik","date":"2020-09-28","format":false,"excerpt":"This is an example of a Windows bat file to run Nastran for every *.dat file in the current folder. It also calculates the total Nastran execution time. Of course, you should change the path to nastran.exe. The nice thing here is that script uses variable set MyPath=%cd%, so you\u2026","rel":"","context":"In &quot;batch&quot;","block_context":{"text":"batch","link":"https:\/\/gantovnik.com\/bio-tips\/category\/batch\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1969,"url":"https:\/\/gantovnik.com\/bio-tips\/2023\/09\/393-count-the-number-of-files-with-a-specific-extension-in-a-folder-using-batch-script\/","url_meta":{"origin":432,"position":2},"title":"#393 Count the number of files with a specific extension in a folder using batch script","author":"gantovnik","date":"2023-09-23","format":false,"excerpt":"[code language=\"python\"] @echo off set count=0 for \/f \"delims=\" %%i in ('dir \/s \/b *.fem') do ( set \/a \"count=count+1\" ) echo Number of fem files in the folder = %count% pause exit 0 [\/code] Output: [code language=\"python\"] Number of fem files in the folder = 20 Press any key\u2026","rel":"","context":"In &quot;batch&quot;","block_context":{"text":"batch","link":"https:\/\/gantovnik.com\/bio-tips\/category\/batch\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":609,"url":"https:\/\/gantovnik.com\/bio-tips\/2020\/08\/91-iterating-through-directories-and-files-inside-these-directories\/","url_meta":{"origin":432,"position":3},"title":"#91 Iterating through directories and files inside these directories","author":"gantovnik","date":"2020-08-13","format":false,"excerpt":"#91 Iterating through directories and files inside these directories [code language=\"python\"] set myDir=\"D:\\lib\" for \/d %%B in (%myDir%\\*) do ( @for %%C in (\"%%B\\*.dat\") do echo %%C) pause [\/code]","rel":"","context":"In &quot;batch&quot;","block_context":{"text":"batch","link":"https:\/\/gantovnik.com\/bio-tips\/category\/batch\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":586,"url":"https:\/\/gantovnik.com\/bio-tips\/2020\/06\/85-how-do-you-loop-in-a-windows-batch-file\/","url_meta":{"origin":432,"position":4},"title":"#85 How do you loop in a Windows batch file?","author":"gantovnik","date":"2020-06-23","format":false,"excerpt":"How do you loop in a Windows batch file? If you want to do something x times, you can do this: Example (x = 200): [code language=\"python\"] FOR \/L %%A IN (1,1,200) DO ( ECHO %%A ) [\/code] 1,1,200 means: [code language=\"python\"] Start = 1 Increment per step = 1\u2026","rel":"","context":"In &quot;batch&quot;","block_context":{"text":"batch","link":"https:\/\/gantovnik.com\/bio-tips\/category\/batch\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":8057,"url":"https:\/\/gantovnik.com\/bio-tips\/2025\/02\/458-hypermesh-tcl-script-to-save-selected-node-ids-and-coordinates-to-a-csv-file\/","url_meta":{"origin":432,"position":5},"title":"#458 HyperMesh tcl script to save selected node IDs and coordinates to a csv file","author":"gantovnik","date":"2025-02-20","format":false,"excerpt":"In this example, we create n=40 random nodes, select several of them, and save their node IDs and coordinates in a csv file. proc RandomReal {min max} { return [expr (rand()*($max-$min)+$min)] } set x_min 0.0 set x_max 20.0 set y_min 0.0 set y_max 10.0 set n 40 for {set i\u2026","rel":"","context":"In &quot;HyperMesh&quot;","block_context":{"text":"HyperMesh","link":"https:\/\/gantovnik.com\/bio-tips\/category\/hypermesh\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2025\/02\/2025-02-20_005944.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2025\/02\/2025-02-20_005944.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2025\/02\/2025-02-20_005944.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2025\/02\/2025-02-20_005944.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2025\/02\/2025-02-20_005944.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2025\/02\/2025-02-20_005944.png?resize=1400%2C800&ssl=1 4x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/432","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/comments?post=432"}],"version-history":[{"count":0,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/432\/revisions"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=432"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=432"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=432"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}