1
$\begingroup$

I have a huge number of identically formatted .txt files. I would like to read some numbers at a specific position within the text file (row x, column y..) and put them in another file, then repeat the procedure for all of my files in order to reduce my huge set of text files to a single txt file which contains the specific parameters that I chose to extract.

I would prefer to do this in mathematica but I have no idea how to read specific data based on the position in the .txt file.

Can any one point me in the right direction with this?

$\endgroup$
2
$\begingroup$

You don't say what you mean by row and column. If you mean characters then this (with better error checking for invalid column number)

character[file_, row_Integer, column_Integer] := 
  StringTake[Import[file, {"Text", "Lines", row}], {column, column}]

If you mean something more structured like CSV contents then:

csvItem[file_, row_Integer, column_Integer] := 
  Import[file, {"Data", row, column}];
$\endgroup$
1
  • $\begingroup$ Thank you for the answer. I mean each character's position is defined by a line number and a column number in a .txt formatted in UTF-8. $\endgroup$ – sqr777 Nov 28 '20 at 15:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.