# Import values from tab separated file, change decimal point?

I have files that look like this:

8853,548600 39,021824
8143,632600 37,200790
7815,964200 35,926544
7106,337000 34,761822
6724,260400 33,491154
6178,100200 32,254318


I want to import it and then change the decimal point from , to . and convert it so that it has the the right head (so I can manipulate it like a number).

My attempt that doesn't work:

data = Apply[StringReplace[#, {"," -> "."}] &,
Import[file, "Data"], {2}]

-

For several reasons I recommend that you do not use VLC's method. First, it is going to be slower than interpreting the data during import, and second it creates the possibility of unintentionally running code via ToExpression.

The most direct and robust method is to specify "NumberPoint" in Import:

Import["file.txt", "Table", "NumberPoint" -> ","]

{{8853.5486, 39.021824},
{8143.6326, 37.20079},
{7815.9642, 35.926544},
{7106.337,  34.761822},
{6724.2604, 33.491154},
{6178.1002, 32.254318}}


For faster importing, at the risk of crashing Mathematica on irregular data, you may make use of the undocumented internal function described here which is actually the subroutine used by Import without all the slow dressing used to auto-detect formats.

table = ReadList["file.txt", Word, RecordLists -> True];

SystemConvertTableDumpParseTable[table, {{{}, {}}, {"-", "+"}, ","}, False]

{{8853.5486, 39.021824},
{8143.6326, 37.20079},
{7815.9642, 35.926544},
{7106.337,  34.761822},
{6724.2604, 33.491154},
{6178.1002, 32.254318}}

-
Good points, never thought about the possibility that some code could be unintentionally executed. I'm going to delete my answer, so nobody will be tempted to use that approach. –  VLC Nov 9 '12 at 10:36
@VLC Please don't; it's a good reference and it illustrates a way to make the method that the OP attempted work. I just think in this case it is not practical. –  Mr.Wizard Nov 10 '12 at 21:25

ToExpression[StringReplace[#, "," -> "."]] & /@
Import[file, "Table"]

-
@Althalos You might reconsider your choice of accepted answer (see Mr.Wizard's answer). –  VLC Nov 9 '12 at 11:35
data= ReadList["!sed 's/,/\./g' /tmp/data.txt", {"Number", "Number"}]
`