Importing a text file of values and converting it to table

I just started using Mathematica. I got some output in a txt file from some computations in Pari/GP which looks like this:

$$[1,2,3,4; 5,6,7,8]$$

Here I want to import the data into Mathematica and get a table. The semicolons indicate a new row and commas separate each entry on a row. I cannot figure out how to do this.

filename = "C:/data.txt";
First@ReadList[filename, Record, RecordSeparators -> {{"["}, {"]"}}] //
StringSplit[#, ";"] & //
Map[Interpreter[DelimitedSequence["Number"]]]


{{1, 2, 3, 4}, {5, 6, 7, 8}}

• This works completely fine when the original matrix has dimensions like 3244 $\times$ 7. But for a row vector, as in the text file being [1,2,3,4], your code gives something like {{1,2,3,4}} with an extra brace, this is not interpreted as a matrix in Mathematica. Commented Jul 25, 2023 at 12:32
• @AdityaGhosh {{1,2,3,4}} is the Matrix in Mathematica. {{1, 2, 3, 4}} // MatrixQ is True. By the way, there not row vector or column vector in vector spaces. row or column only in Matrix. Commented Jul 25, 2023 at 12:38
• Evaluate: {Dimensions@#, MatrixQ@#} &@{{1, 2, 3, 4}}. Thanks for the comment by @cvgmt.
– Syed
Commented Jul 25, 2023 at 12:38
• I think using Catenate solves the issue for me, as it removes that extra brace Commented Jul 25, 2023 at 12:40

First we import the data as a string:

filename="d:/tmp/test.dat";
tmp=Import[filename][[1, 1]];


tmp= StringReplace[tmp , {"[" -> "{{", "]" -> "}}", ";" -> "},{"}]

ToExpression[tmp] // TableForm