Solved rearrange columns in a text file line by line

Dell / Dell dxp051...
July 6, 2011 at 08:19:02
Specs: Microsoft Windows XP Professional, 2.793 GHz / 2046 MB
I'm wanting to take the columns in a text file and output them to another text file in a different order. I am able to do this to the first line, but not for every line in the file.
So far I have:

@echo off
setLocal EnableDelayedExpansion
for /f "tokens=1-4 delims=: " %%g in ("%time%") do set time_stamp=%%g%%h
set /p var=<file1.txt
set N=
for /f "tokens=* delims= " %%a in (file1.txt) do (
set/a N=N+1
set var1=!var:~0,15!
set var2=!var:~15,15!
set var3=!var:~30,16!
echo %date% %time_stamp% !var3!!var2!!var1! >> file3.txt
)
----------------------------------------------------------------------------
this will give something like
07/06/2011 0905 c b a
07/06/2011 0905 c b a
07/06/2011 0905 c b a
07/06/2011 0905 c b a
in file3.txt, but I need it to keep going for something like

07/06/2011 0905 c b a
07/06/2011 0905 f e d
07/06/2011 0905 i h g
07/06/2011 0905 l k j


See More: rearrange columns in a text file line by line

Report •


#1
July 6, 2011 at 11:45:44
also, the file it'll be reading from is a Fixed Length file. That's why I'm looking at the columns by position instead of a regular delimiter.

Report •

#2
July 6, 2011 at 12:27:09
✔ Best Answer

@echo off
setLocal EnableDelayedExpansion
for /F "tokens=1-4 delims=: " %%g in ("%time%") do set time_stamp=%%g%%h
for /F "delims=" %%a in (file1.txt) do (
set /A N+=1
set var=%%a
set var1=!var:~0,15!
set var2=!var:~15,15!
set var3=!var:~30,16!
echo %date% %time_stamp% !var3!!var2!!var1! >> file3.txt
)
echo.%N%


Report •

#3
July 6, 2011 at 13:27:07
Thanks, it's working now.

Report •
Related Solutions


Ask Question