I have a txt file "data.txt". This contain data like
a 1 b 2 c 3 I want to import this file into two list like $\{a,b,c\}$ and $\{1,2,3\}$.I have tried using SplitBy, but no luck.
list=Import["finename.txt", "Table"] should do the trick. With the following you should be able to assign values, i.e get a list of explicit assigned values
MapIndexed[(x[#2[[1]]] = #1[[2]]) &, list]; You can use
?x to check that.
Edit
If you want an array I think the following should do the trick:
x=list[[All, 2]]; d3 = ReadList["C:/data.txt", Record, RecordSeparators -> {"\n"}, WordSeparators -> {"\t", " "}] {"a 1", "b 2", "c 3"}
Now you can convert this list of strings to expressions and execute Transpose (assuming that's what you want);
Transpose@ToExpression@(StringSplit /@ d3) {{a, b, c}, {1, 2, 3}}
Not sure what representations you eventually want, but if you import it as a string...
data = Import[pathtofile] ...then you can start with StringSplit...
list = StringSplit[data] ...from there you can partition and reorganize...
Transpose[Partition[list, 2]] Now, the individual elements are still strings, but I don't know what you want them to be. You may need to apply more transformations or you may want to use import options.
One possibility :
data = "a 1 b 2 c 3"; file = Export[FileNameJoin[{$TemporaryDirectory, "test.txt"}], data] ReadList[file, Word, RecordLists -> True] {{"a", "1"}, {"b", "2"}, {"c", "3"}}
Then use Transpose