Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

You're looking for Skip. This does not check for an EndOfFile condition, and should use something like BlockStreamBlockStream to handle aborts, but the following should work:

strm = OpenRead["filename"];

(* Repeat the following until done *)

Skip[strm, String, A];    
AppendTo[ results, Read[strm, String]]

(* 
  String just gets the entire line. If the number of elements is 
  constant for each row, then it can be replaced in the Read by   
  ConstantArray[String, numels]~Join~{String}. 
*)

Skip[strm, String, B - 2];
AppendTo[ results, Read[strm, String]]

(* close the stream *)
Close[ strm ];

You're looking for Skip. This does not check for an EndOfFile condition, and should use something like BlockStream to handle aborts, but the following should work:

strm = OpenRead["filename"];

(* Repeat the following until done *)

Skip[strm, String, A];    
AppendTo[ results, Read[strm, String]]

(* 
  String just gets the entire line. If the number of elements is 
  constant for each row, then it can be replaced in the Read by   
  ConstantArray[String, numels]~Join~{String}. 
*)

Skip[strm, String, B - 2];
AppendTo[ results, Read[strm, String]]

(* close the stream *)
Close[ strm ];

You're looking for Skip. This does not check for an EndOfFile condition, and should use something like BlockStream to handle aborts, but the following should work:

strm = OpenRead["filename"];

(* Repeat the following until done *)

Skip[strm, String, A];    
AppendTo[ results, Read[strm, String]]

(* 
  String just gets the entire line. If the number of elements is 
  constant for each row, then it can be replaced in the Read by   
  ConstantArray[String, numels]~Join~{String}. 
*)

Skip[strm, String, B - 2];
AppendTo[ results, Read[strm, String]]

(* close the stream *)
Close[ strm ];
Source Link
rcollyer
  • 34.1k
  • 7
  • 94
  • 194

You're looking for Skip. This does not check for an EndOfFile condition, and should use something like BlockStream to handle aborts, but the following should work:

strm = OpenRead["filename"];

(* Repeat the following until done *)

Skip[strm, String, A];    
AppendTo[ results, Read[strm, String]]

(* 
  String just gets the entire line. If the number of elements is 
  constant for each row, then it can be replaced in the Read by   
  ConstantArray[String, numels]~Join~{String}. 
*)

Skip[strm, String, B - 2];
AppendTo[ results, Read[strm, String]]

(* close the stream *)
Close[ strm ];