title: Batch Scripting - Search for value in text file and copy word next to it
body: <p>Currently writing a batch program but I seem to be having a difficult time with string manipulation. I need help scanning through the contents of the Output.txt file below, in search of the the word ssudmdm. wherever the word is found, i then need to retrieve the com value on the same line, to the right and store it in a variable. 
  I am aware that there are a few examples on the site, however I have have tried implementing them with no luck. Any help would be appreciated.</p>
  
  <p>Code:-----------------------------------------------</p>
  
  <pre><code>@ECHO OFF
  
  :: Use local environment copy
  SETLOCAL
  ::regedit.exe /S VM_Putty_Settings.reg
  
  :while1
  
  reg QUERY "HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM" &gt; Output.txt
  
  @start /wait FIND /C /I "ssudmdm" Output.txt
  
  if %ERRORLEVEL% == 1 (  
      timeout /t 2 &gt;nul
      goto :while1
      )
  
  
  for /f "tokens=3" %%a in ('find /i "ssudmdm" output.txt') do set var=%%a
  
  reg add "HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\VM_Putty_Settings" /V SerialLine /T REG_SZ /D "%var%" /F
  
  pause
  start Putty.exe -load VM_Putty_Settings &lt; nul &gt;NUL 2&gt;NUL
  
  
  ENDLOCAL
  GOTO:EOF
  </code></pre>
  
  <p>Output file----------------------------------</p>
  
  <pre><code>HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM
      \Device\Serial0    REG_SZ    COM1
      \Device\Serial1    REG_SZ    COM2
      \Device\ssudserd0000    REG_SZ    COM5
      \Device\ssudserd0001    REG_SZ    COM6
      \Device\ssudmdm0000    REG_SZ    COM7
  </code></pre>