Solved batch script to align the columns in a text file.

January 7, 2015 at 13:35:27
Specs: Windows 7
Hello, Below is my problem:

The data in my file is like this:

98869 0000390.00 QRP
178411 0000015.00 QRP

I need it like the below:

 96782 0000015.00 QRP
100266 0000015.00 QRP

Below is the code currently I am using:

@echo off
if exist c:\Newfile.dat del c:\Newfile.dat
for /F "skip=1 delims=" %%a in (C:\test\Bonus_File_Export.txt) do call :Sub %%a
goto :eof

echo %1 %2 %3>>c:\test\Newfile.dat

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.

Do let me know if any information is needed from my side. Any help is highly appreciated. Thank you.

edited by moderator: Added pre tags. -Razor2.3

See More: batch script to align the columns in a text file.

Report •

January 7, 2015 at 13:38:33
The part under the comment "I need it like the below" is not showing properly.

the value "96782" should start leaving a space at the beginning and will end at the same point as the next line.

Report •

January 7, 2015 at 18:18:41
Since this is probably school-work, I'll just give the "quick-and-funky":
set /p a=enter a number
set a=               %A%
set a=%a:~-6%
echo right justified: 6 blanks:%a%]

Had to laugh! OP not only one to forget "pre" tag!

message edited by nbrane

Report •

January 7, 2015 at 21:43:55
✔ Best Answer
:: put space before first column if it's 5 chars
::======  script starts here  ===============
:: align.bat  2015-01-08 12:23:22.45
@echo off > NEWFILE & setLocal enableDELAYedeXpansioN

for /f "tokens=1-3 " %%a in (myfile) do (
set S=%%a
set S=!S:~5,1!
if "!S!" equ "" (
echo  %%a %%b %%c
) else (
echo.%%a %%b %%c
goto :eof

::======  script ends here  =================

M2 Golden-Triangle

Report •

Related Solutions

Ask Question