title: How do I extract a certain part of each string in a list of strings in batch script?
body: <p>I have the output of a command </p>
  
  <pre><code>reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" 
  </code></pre>
  
  <p>which I need to:</p>
  
  <p>1) Filter to include only TrueType fonts</p>
  
  <p>2) Shorten down the output to only include the font's name (everything up to the "(TrueType)")</p>
  
  <p>Is it possible to do this, and if so, how?</p>
  
  <p>I've already tried using</p>
  
  <pre><code>reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" | 
  findstr /I /C:"(TrueType)"
  </code></pre>
  
  <p>and got the output</p>
  
  <pre><code>Arial (TrueType)    REG_SZ    arial.ttf
  Arial Black (TrueType)    REG_SZ    ariblk.ttf
  Arial Bold (TrueType)    REG_SZ    arialbd.ttf
  Arial Bold Italic (TrueType)    REG_SZ    arialbi.ttf
  Arial Italic (TrueType)    REG_SZ    ariali.ttf
  ect.
  </code></pre>
  
  <p>but from there I couldn't figure out how to omit the filenames and the "REG_SZ" text. I tried setting them all to variables with help from <a href="https://stackoverflow.com/questions/6359820/how-to-set-commands-output-as-a-variable-in-a-batch-file">this</a> post</p>
  
  <pre><code>SETLOCAL ENABLEDELAYEDEXPANSION
  SET count=1
  FOR /F "tokens=* USEBACKQ" %%F IN (`reg query 
  "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" | 
  findstr /I /C:"(TrueType)"`) DO (
    SET var!count!=%%F
    SET /a count=!count!+1
  )
  ECHO %var1%
  ECHO %var2%
  ECHO %var3%
  ENDLOCAL
  </code></pre>
  
  <p>But again, this wouldn't work because each computer has a different amount of fonts, so there's no set amount of variables to assign. Also, the files for each font have different amounts of characters in the filename, so using</p>
  
  <pre><code>echo %var1:~,-X%
  </code></pre>
  
  <p>wouldn't work, nor would the opposite</p>
  
  <pre><code>echo %var1:~,X%
  </code></pre>
  
  <p>So ultimately, I'm back to square one with</p>
  
  <pre><code>reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" | 
  findstr /I /C:"(TrueType)"
  </code></pre>
  
  <p>Is there any way to achieve the outcome I need?</p>