# How to remove brackets from a data file

I would like to know how I can transform a file (.dat) that contains

{x1,x2, x3, x4,
x5, x6, x7, x8}
{y1,y2, y3, y4,
y5, y6, y7, y8}


in another file (.dat) that contains

x1 x2 x3 x4 x5 x6 x7 x8
y1 y2 y3 y4 y5 y6 y7 y8

• Does the existing file look exactly the way you show it? That is, does its 1st line have linefeed character after rightmost comma and does the 2nd line begins a single space? – m_goldberg Sep 13 at 18:53
• Can you just do Export[secondFile, Import[firstFile, "Package"], "Table"]? – b3m2a1 Sep 13 at 19:22

Here is one option using text manipulations.

data = Import["test.dat", "Text"]


"{x1,x2, x3, x4, x5, x6, x7,x8} {y1,y2, y3, y4, y5, y6, y7,y8}"

data2 = "{" <> StringReplace[StringReplace[data, WhitespaceCharacter -> ""],
"}{" -> "},{"] <> "}"


"{{x1,x2,x3,x4,x5,x6,x7,x8},{y1,y2,y3,y4,y5,y6,y7,y8}}"

Export["test.txt", ToExpression[data2], "Table"];


The resulting text file looks like this: