| 1. |
Solve : batch script to align the columns in a text file.? |
|
Answer» Hello, Below is my problem: Yes Sir, I've gone through this link a while ago. A tried a bit but my code failed with syntax errors as I was not using them properly. Could you please guide me with this?So you tried using this function already? Why didn't you ask for help on the Dostips.com forum if you couldn't get it too work? Code: [Select]echo off &setlocal enabledelayedexpansion if exist Newfile.txt del Newfile.txt for /F "tokens=1-3" %%G in (file.txt) do ( call :Format "[-6][-18][-4]" %%G %%H %%I >>Newfile.txt echo !line! ) goto :eof :Format fmt str1 str2 ... -- outputs columns of strings right or left aligned :: -- fmt [in] - format string specifying column width and alignment, i.e. "[-10][10][10]" :$created 20060101 :$changed 20091130 :$categories Echo :$source http://www.dostips.com SETLOCAL set "fmt=%~1" set "line=" set "spac= " set "i=1" for /f "tokens=1,2 delims=[" %%a in ('"echo..%fmt:]=&echo..%"') do ( set /a i+=1 call call set "subst=%%%%~%%i%%%spac%%%%%~%%i%%" if %%b0 GEQ 0 (call set "subst=%%subst:~0,%%b%%" ) ELSE (call set "subst=%%subst:~%%b%%") call set "const=%%a" call set "line=%%line%%%%const:~1%%%%subst%%" ) endlocal&set "line=%line%" GOTO :EOF output Code: [Select]C:\BatchFiles\Format>type file.txt 96782 0000015.00 QRP 100266 0000015.00 QRP C:\BatchFiles\Format>format_SSIS.bat C:\BatchFiles\Format>type newfile.txt 96782 0000015.00 QRP 100266 0000015.00 QRP C:\BatchFiles\Format> Quote from: ssis_sql_dev on January 07, 2015, 02:15:14 PM Hello, Below is my problem: The numbers are different - is that part of the task? Quote from: ssis_sql_dev on January 07, 2015, 02:15:14 PM how to enhance this code to make sure that, when there is a 5 digit value shows up, it will be like the one I need. What do you mean by this? Will there be 4 digit numbers for example? The task is not clear from what you have written. |
|