Need help in transposing rows

February 16, 2009 at 00:19:05
Specs: Windows XP, 1GB
Hi guys,

currently i have a list of over 6000 contact of info in this form below

Name : tom
address : 49 cedar point
state : ohio
COuntry : USA
Name : jerry
address : 32 cedar point
state : ohio
COuntry : USA
Name : henry
address : 23 washinton
state : LA
COuntry : USA


How do i transpose it into this format in the fastest way?

Name Address state Country
Tom 49 cedar.. Ohio USA
Jerry 32 cedar.. Ohio USA
Henry 23 washin.. LA USA


I am able to do it for a few rows. However is there any faster way for me to repeat this process as i have over 1000 contacts?

Many thanks.


See More: Need help in transposing rows

Report •


#1
February 16, 2009 at 03:37:34
yuanhe,

Try this. Assumption is that all new entries start with the tag "Name :" (note the space after 'Name' before the ':'.
adrs.txt is the input file and outAdrs.txt is the output file.

setlocal enabledelayedexpansion
for /f "delims=: tokens=1,2*" %%I in (adrs.txt) do (
if "%%I"=="Name " echo. >> outAdrs.txt
set /p t=%%J <nul >> outAdrs.txt
)

--
Holla.


Report •

#2
February 16, 2009 at 04:01:26
@echo off & setLocal EnableDelayedExpansion

> newfile echo Name Address state Country

for /f "tokens=1* delims=: " %%a in (myfile) do (
set /a N+=1
set v!N!=%%b
if !N! equ 4 (
>> newfile echo !v1! !v2! !v3! !v4!
set N=0
)
)


=====================================
If at first you don't succeed, you're about average.

M2


Report •

Related Solutions


Ask Question