Note that there are some explanatory texts on larger screens.

plurals
  1. POSearch for a list of words in a file, then find those words on another replacing the whole line with Class=ShipDummy,replacing the 2 lines below it
    primarykey
    data
    text
    <p>I'd like to search for a list of words from an external list (simple each word on a line) which we'll call "List.txt", and search for them in a file (C:\Users\P Ditty\Documents\SH3\data\cfg\Backups_SCR*.clg) <em>(matching the whole word, even if it's inside another, and matching case)</em>, then if they are there find those words on another file(Campaign_SCR.mis.tmp) <em>(matching the whole word even if its inside another, matching case)</em> replacing the whole line in (Campaign_SCR.mis.tmp) with Name=ShipDummy ONLY if the line starts with "Name=". After that the two lines below that in that same file would be replaced with 2nd line "Class=ShipDummy", then 3rd line "Type=206".</p> <p>Here is the code I have now. Now it searches for ClassName=<strong>Variable</strong> in C:\Users\P Ditty\Documents\SH3\data\cfg\Backups_SCR*.clg, then it replaces the whole line with Class=ShipDummy if it finds the variable in Campaign_SCR.mis.tmp. It also replaces 1 line below it with "Type=206".</p> <pre><code>setlocal enableDelayedExpansion &gt;Campaign_SCR.mis.tmp ( for /f "tokens=1* delims=:" %%A in ('findstr /n "^" Campaign_SCR.mis.backup') do ( ( echo !ln!| findstr "^Type=12$" &gt;NUL &amp;&amp; set ln=ln ) || ( set "ln=%%B" if "!ln:~0,6!"=="Class=" ( findstr /s /c:"ClassName=!ln:~6!" "C:\Users\P Ditty\Documents\SH3\data\cfg\Backups_SCR\*.clg" &gt;"C:\Users\P Ditty\Documents\SH3\data\cfg\Backups_SCR\null" &amp;&amp; ( echo Class=ShipDummy set "ln=Type=12" ) ) if #!ln!==# (echo;) else echo !ln! ) ) ) </code></pre> <p><strong>BUT I'd like it to search for a name from a list I specify, search in (C:\Users\P Ditty\Documents\SH3\data\cfg\Backups_SCR*.clg). Then if it finds the match, then search for that in Campaign_SCR.mis.tmp and replace the whole line, only if that line starts with "Name=", with Name=ShipDummy. The two lines below that would be replaced with 2nd line "Class=ShipDummy", then 3rd line "Type=206":</strong></p> <pre><code>Name=ShipDummy Class=ShipDummy Type=206 </code></pre> <p>**Please keep in mind that within Campaign_SCR.mis.tmp the variable's line wont often appear as Name=variable. It is likely to be Name=(words)variable(words)</p> <p>Can the list that is searched be external? Can we make it search one word per line. For exmaple: if the list is as follows:</p> <p>Bismarck Hood Repulse</p> <p>It will search for each word.**</p> <p><strong>When it matches the words from the list to (C:\Users\P Ditty\Documents\SH3\data\cfg\Backups_SCR*.clg) please ensure that it matches case as well. So "Bismarck" from list will find "Bismarck" from (C:\Users\P Ditty\Documents\SH3\data\cfg\Backups_SCR*.clg), and not find "bismarck"</strong></p> <p>Thank you for your time!</p> <p>By the way, this may be a simpler workaround to the problem I have here: <a href="https://stackoverflow.com/questions/15017118/how-do-i-apply-this">How do I apply this?</a></p> <p><strong>So for example:</strong></p> <p>Say I have an external list (call it List.txt for example) that looks like this:</p> <pre><code>Bismarck Hood Repulse </code></pre> <p>I will search C:\Users\P Ditty\Documents\SH3\data\cfg\Backups_SCR*.clg for that. Say it finds "Bismarck" and "Hood" in this:</p> <pre><code>sadfasfasfdBismarckfasdfasdfasdfas asdfasfdafHoodasdfasfas </code></pre> <p>Then it will search Campaign_SCR.mis.tmp for Bismarck and Hood replacing:</p> <pre><code>Name=asdfBismarckasfdw Class=jlkjf Type=12 </code></pre> <p>With:</p> <pre><code>Name=ShipDummy Class=ShipDummy Type=206 </code></pre> <p>And</p> <pre><code>Name=asdfHoodasfdw Class=jlkjf Type=13 </code></pre> <p>With:</p> <pre><code>Name=ShipDummy Class=ShipDummy Type=206 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload