Hi has a text file that is like below newyork - karen,d1,d2
london - johni,a1,a2
europe - alex,h1,h2Wanted to make the text file into
newyork - karen
d1
d2
london - johni
a1
a2
europe - alex
h1
h2
How to do this?
perl -pe "s/,/\n/g" file.txt or
perl -Mv5.10 -F, -ane "say $_ for @F" file.txt
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
@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 ?
@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.
@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.