Text file adjustment column to row

September 5, 2010 at 03:13:39
Specs: Windows XP
Hi has a text file that is like below

newyork - karen,d1,d2
london - johni,a1,a2
europe - alex,h1,h2

Wanted to make the text file into

newyork - karen
d1
d2
london - johni
a1
a2
europe - alex
h1
h2

How to do this?


See More: Text file adjustment column to row

Report •


#1
September 5, 2010 at 07:40:59
perl -pe "s/,/\n/g" file.txt

or

perl -Mv5.10 -F, -ane "say $_ for @F" file.txt


Report •

#2
September 5, 2010 at 07:53:28
download sed for windows then do this

c:\test> sed 's/[ \t]*,[ \t]*/\n/g' file

GNU win32 packages | Gawk


Report •

#3
September 5, 2010 at 14:57:00
In plain old batch script:

@echo off
cls
setlocal 

for /f "tokens=1-2* delims=," %%1 in (input.txt) do (
    echo %%1
    echo %%2
    echo %%3
    )>>output.txt



Report •

Related Solutions

#4
September 5, 2010 at 17:49:31
@Wahine, what is the syntax for iterating the %%1 tokens? How many tokens can it take? is there a way to do it without specifying %%1, %%2, but instead do it dynamically ?

GNU win32 packages | Gawk


Report •

#5
September 5, 2010 at 21:14:37
@ghostdog - How many tokens can it take?

I understand the max value for Tokens is 31 and that the %%n variables used can be represented by almost any printable characters in the Ascii and Extended Ascii. There are a few exceptions. The number of variables which can be open at any one time exceeds 60.

@ghostdog - is there a way to do it without specifying %%1, %%2, but instead do it dynamically ?

Possibly, I have never had occasion or need to investigate that.


Report •

#6
September 5, 2010 at 22:05:36
@wahine, the reason i ask is that it would be nice if your batch can cater for more than 3 tokens, eg
newyork - karen,d1,d2,d3.....,d32

that way, it takes care of it no matter how many values separated by commas the OP's data has.

GNU win32 packages | Gawk


Report •


Ask Question