title: How to get the last word in the last line in a file with Windows batch script?
body: <p>I have a file <code>sample.txt</code> with the content as below.</p>
  
  <pre><code>H|20170331|CIS
  A||A1140|GRM  //header
  A||A1140|GRM
  A||A1140|GRM
  A||A1140|GRM
  A||A1140|GRM
  T|20170331|5  //trailer
  </code></pre>
  
  <p>I need the last token in the last line i.e. <code>5</code>. <em>(It's the count of the line except header trailer)</em>.</p>
  
  <p>As of now, I tried below; it's giving the first token, i.e. <code>T</code>, but I need the last token i.e. <code>5</code>.</p>
  
  <pre><code>@echo off
  rem for /f "skip=1 tokens=2,* delims=" %%a in (sample.txt) do set "variable=%%a"
  
  rem for /f "delims=|" %%x in (sample.txt) do set "variable=%%x"
  for /f "delims=|" %%G in (sample.txt) do set "variable=%%G"
  echo %variable%
  
  pause
  </code></pre>
  
  <p>Note the file can contain thousands of records so the last token is required.</p>