Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The code line


should be executed in a Module at first.
The Module consists of a Slider and a Pane.
The Slider positions a StreamPosition in file.
The Module then reads a chunk of records from that file.
The external file is a txt file with variable length string records.

The Slider value for the ReadList is just a rough position.
For it is in lack of the knowledge of well defined record start positions.
The unwanted result:
enter image description here

Therefore the Module has to adjust in a first step to the begin of a
record with Read[str,Record]. The first record displayed in Pane
will be the complete one. Should give this result:

enter image description here

Note: The files start position - it's 1. record - is aligned and
does not need that correction.

enter image description here

Where to integrate it and how to bring to life the Read[] in this Module?

infil = "F:\\LargeDataSet\\Entwicklung\\Daten Beispiele\\test 1M \
semicolon key.txt";
panerows = 200;
str = OpenRead[infil, BinaryFormat -> True];
filebytes = FileByteCount[infil];
recbytes = Round[filebytes/anzrecs - 2];
erst = 1;
n1 = (erst - 1)*recbytes;  

  {Dynamic[SetStreamPosition[str, n1]],
   Slider[Dynamic[n1], {0, maxbyte, recbytes}, ImageSize -> 400, 
    Appearance -> Small],
   Pane[Column /@ Dynamic[ReadList[str, Record, 200 + n1 - n1]],
    ImageSize -> {400, 200}, Scrollbars -> True]}
share|improve this question
Hi, your code doesn't work when pasted (missing the definitions of maxbyte and anzrecs, and, of course the file, which is understandable). – Michael E2 May 1 '13 at 12:43

If you put Read[str, Record, 1] in before, it will align the stream with the next record.

Pane[Column /@ 
  Dynamic[ReadList[str, Record, 1]; 
   ReadList[str, Record, 200]], ImageSize -> {400, 200}, 
 Scrollbars -> True]

Does that help? (Tested with infil = "/usr/share/dict/words").

If it's a small file, you could preprocess an index of record positions:

SetStreamPosition[str, 0];
idx = Reap[NestWhile[(Sow[StreamPosition[str]]; ReadList[str, Record, 1]) &, 
     0, # =!= {} &]][[-1, 1]];

 Column[{Dynamic[SetStreamPosition[str, idx[[n1]]]], 
   Slider[Dynamic[n1], {1, Length[idx] - 200, 1}, ImageSize -> 400, 
    Appearance -> Small], 
   Pane[Column /@ Dynamic[ReadList[str, Record, 200]], 
    ImageSize -> {400, 200}, Scrollbars -> True]}]]

If it's a large file, you could do it once and store the index in an auxiliary file.

Alternatively, for a small file, you can read in the whole file as a String and split it into records.

db = StringSplit[Import[infil, "String"], "\r" | "\n"];

   Slider[Dynamic[n1], {1, Length[db] - 199, 1}, ImageSize -> 400, 
    Appearance -> Small], 
   Pane[Column /@ Dynamic[db[[n1 ;; n1 + 199]]], 
    ImageSize -> {400, 200}, Scrollbars -> True]}]]
share|improve this answer
Yes. . .It is for very huge files. . .I could use your suggestion, modified it and it works well. – Hp Radojewski Schäfer Von May 3 '13 at 9:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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