computing
  • 7

Truncate Last Characters Of a String In Txt F

  • 7

Hi,

I am trying to create a batch file which will read a text file, and delete last four characters from the text in it…ie
file will read test.txt for mynameis.txt
batch file will change it to
mynameis and store it as a variable

Share

1 Answer

  1. at command prompt, see: for /?
    set /?
    setlocal /?
    that you you’ll know what’s going on here.
    here’s the quickie version:

    @echo off & setlocal enabledelayedexpansion
    for /f “tokens=*” %%a in (file.txt) do (
    set xx=%%a
    set xx=!xx:~0,-4!
    echo.!xx!
    )

    • 0