Computing Staff
  • 13

Reading And Writing Text File Using Windows Batch

  • 13

I had a txt file which has a line of 135 char length each, I need a windows batch whic will read the input file line by line and writ it to the output txt file by splitting the line in to tw like 72 char and 64 chars, ie splitting the line in to two and writing it out

Share

1 Answer

  1. This gets 72 and ‘the rest’, whatever ‘the rest’ happens to be.
    ::====== script starts here ===============
    ::
    :: Dansplit.bat 2015-09-10 12:55:13.79
    @echo off > NEWFILE & setLocal enableDELAYedeXpansioN

    :main
    for /f “tokens=* delims= ” %%a in (myfile) do (
    set S=%%a
    set H=!S:~0,72!
    set T=!S:~72!
    echo.!H!
    echo.!T!
    ) >> NEWFILE
    goto :eof
    ::====== script ends here =================

    =====================

    • 0