title: Formatting text in Windows Batch file and redirect to a text file
body: <p>I have a windows 7 batch script which launches a test app and writes the results to a result.txt file. After each test case is executed, I am parsing the outcome of each test case and appending (>> command) the result to result.txt file.</p>
  
  <p><strong>What I need:</strong>
  I need to output the results to result.txt in pretty text format. How can I do it in batch file ?</p>
  
  <p>The snippet (only two test cases here for example) of my script is as below:</p>
  
  <pre><code>REM 1. AboutScreenEnglishTest:
  adb shell am instrument -w -r -e debug false -e class com.innovapost.stv.ui.activity.AboutScreenEnglishTest com.innovapost.stv.test/android.support.test.runner.AndroidJUnitRunner | FIND "FAILURES!!!" &gt; NUL
  if %errorlevel% == 0 (
  ECHO 01. %Date%_%Time%: AboutScreenEnglishTest -- FAILED* &gt;&gt; %RESULTFILENAME%
  ) else (
  ECHO 01. %Date%_%Time%: AboutScreenEnglishTest -- PASSED &gt;&gt; %RESULTFILENAME%
  )
  
  REM 2. AboutScreenFrancaisTest:
  adb shell am instrument -w -r -e debug false -e class com.innovapost.stv.ui.activity.AboutScreenFrancaisTest com.innovapost.stv.test/android.support.test.runner.AndroidJUnitRunner | FIND "FAILURES!!!" &gt; NUL
  if %errorlevel% == 0 (
  ECHO 02. %Date%_%Time%: AboutScreenFrancaisTest -- FAILED* &gt;&gt; %RESULTFILENAME%
  ) else (
  ECHO 02. %Date%_%Time%: AboutScreenFrancaisTest -- PASSED &gt;&gt; %RESULTFILENAME%
  )
  </code></pre>
  
  <p>This gives me the <strong>actual result.txt</strong> file output as below:</p>
  
  <pre><code>    Automated Test launched at: 2018-03-16_23:44:47.19 
      -------Package push and installation------------------------------------------
      2018-03-16_23:44:47.21: Pushing UiTest.apk to Test Phone 
      2018-03-16_23:44:59.85: Installation of UiTest.apk -- SUCCESS 
      -------End of package push and installation-----------------------------------
  
      Test starts here...
      No. Time of test            Test case title           Result
      --- ----------------------- ----------------------    ------
      01. 2018-03-16_23:45:23.24: AboutScreenEnglishTest -- PASSED 
      02. 2018-03-16_23:45:34.36: AboutScreenFrancaisTest -- PASSED 
      03. 2018-03-16_23:45:44.69: DebugScreenEnglishTest -- PASSED 
      04. 2018-03-16_23:45:56.23: DebugScreenFrancaisTest -- PASSED 
      05. 2018-03-16_23:46:08.67: LoadDetailsEnglishTest -- FAILED* 
      06. 2018-03-16_23:46:20.74: LoadDetailsFrancaisTest -- FAILED* 
      07. 2018-03-16_23:46:35.64: LoadServiceEnglishTest -- PASSED 
      08. 2018-03-16_23:46:53.54: LoadServiceFrancaisTest -- PASSED 
      09. 2018-03-16_23:47:06.25: LoadServiceInfoEnglishTest -- FAILED* 
      10. 2018-03-16_23:47:20.42: LoadServiceInfoFrancaisTest -- FAILED* 
      11. 2018-03-16_23:47:32.47: LoginEnglishTest -- PASSED 
      12. 2018-03-16_23:47:46.65: LoginFrancaisTest -- PASSED 
      13. 2018-03-16_23:47:58.66: MenuScreenEnglishTest -- PASSED 
      14. 2018-03-16_23:48:12.67: MenuScreenFrancaisTest -- PASSED 
      15. 2018-03-16_23:48:27.14: Training_LoadDetailsEnglishTest -- FAILED* 
      16. 2018-03-16_23:48:43.96: Training_LoadDetailsFrancaisTest -- FAILED* 
      17. 2018-03-16_23:49:03.54: Training_LoadServiceEnglishTest -- PASSED 
      18. 2018-03-16_23:49:23.52: Training_LoadServiceFrancaisTest -- PASSED 
      19. 2018-03-16_23:49:38.96: Training_LoadServiceInfoEnglishTest -- FAILED* 
      20. 2018-03-16_23:50:33.62: Training_LoadserviceInfoFrancaisTest -- FAILED* 
  </code></pre>
  
  <p>But I would like the <strong>result.txt</strong> should looks like this. (Note that, the 'Test case title' length varies from test case to case, and my test app is incrementally including new test cases every day):</p>
  
  <pre><code>Automated Test launched at: 2018-03-16_23:44:47.19 
  -------Package push and installation------------------------------------------
  2018-03-16_23:44:47.21: Pushing UiTest.apk to Test Phone 
  2018-03-16_23:44:59.85: Installation of UiTest.apk -- SUCCESS 
  -------End of package push and installation-----------------------------------
  
  Test starts here...
  No. Time of test            Test case title                      Result
  --- ----------------------- ----------------------               ---------
  01. 2018-03-16_23:45:23.24: AboutScreenEnglishTest               -- PASSED 
  02. 2018-03-16_23:45:34.36: AboutScreenFrancaisTest              -- PASSED 
  03. 2018-03-16_23:45:44.69: DebugScreenEnglishTest               -- PASSED 
  04. 2018-03-16_23:45:56.23: DebugScreenFrancaisTest              -- PASSED 
  05. 2018-03-16_23:46:08.67: LoadDetailsEnglishTest               -- FAILED* 
  06. 2018-03-16_23:46:20.74: LoadDetailsFrancaisTest              -- FAILED* 
  07. 2018-03-16_23:46:35.64: LoadServiceEnglishTest               -- PASSED 
  08. 2018-03-16_23:46:53.54: LoadServiceFrancaisTest              -- PASSED 
  09. 2018-03-16_23:47:06.25: LoadServiceInfoEnglishTest           -- FAILED* 
  10. 2018-03-16_23:47:20.42: LoadServiceInfoFrancaisTest          -- FAILED* 
  11. 2018-03-16_23:47:32.47: LoginEnglishTest                     -- PASSED 
  12. 2018-03-16_23:47:46.65: LoginFrancaisTest                    -- PASSED 
  13. 2018-03-16_23:47:58.66: MenuScreenEnglishTest                -- PASSED 
  14. 2018-03-16_23:48:12.67: MenuScreenFrancaisTest               -- PASSED 
  15. 2018-03-16_23:48:27.14: Training_LoadDetailsEnglishTest      -- FAILED* 
  16. 2018-03-16_23:48:43.96: Training_LoadDetailsFrancaisTest     -- FAILED* 
  17. 2018-03-16_23:49:03.54: Training_LoadServiceEnglishTest      -- PASSED 
  18. 2018-03-16_23:49:23.52: Training_LoadServiceFrancaisTest     -- PASSED 
  19. 2018-03-16_23:49:38.96: Training_LoadServiceInfoEnglishTest  -- FAILED* 
  20. 2018-03-16_23:50:33.62: Training_LoadserviceInfoFrancaisTest -- FAILED* 
  </code></pre>