let succ_str s =
  try (string_of_int (int_of_string s + 1))
  with Failure _ -> s

let read scanbuf f =
  let t = "\t"  and nl = "\n"  in
  Scanf.bscanf scanbuf "%[^\t]\t%[^\t]\t%[^\t]\t%[^\n]%c"
  (fun a b c d _ -> f [a;t;c;t;b;t; succ_str d; nl])  

let f ch =
  let accu = ref [] in
  try
    read ch (List.iter print_string);
    while true do
      (read ch (fun l -> accu := l::!accu))
    done;
  with End_of_file ->
    let l = List.stable_sort (fun a b ->
      compare (List.hd a) (List.hd b)) !accu
    in List.iter (List.iter print_string) l;;
(*  
let s = "\
ID\tSurname\tForename\tAge
1\tSato\tHanako\t17
0\tSuzuki\tTaro\t18
"
let (path,o) = 
  Filename.open_temp_file "doukaku209_" ".txt";;
output_string o s;  close_out o;;

let sbuf = Scanf.Scanning.from_file path in (f sbuf);;
*)