Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] sort a file by a field

Expand Messages
  • Charles K. Clarkson
    From: Denny Malloy ... Oh sure! NOW you tell me: my %raw_file; my $in_file = in.txt ; my $sorted_file = out.txt ; open (RAW,
    Message 1 of 5 , Mar 1, 2001
      From: "Denny Malloy" <denny.malloy@...>
      : Hi
      : What you sent works but there is still one problem. My file can have more
      : than one of the same social security number.

      Oh sure! NOW you tell me:

      my %raw_file;
      my $in_file = 'in.txt';
      my $sorted_file = 'out.txt';
      open (RAW, $in_file) || die "Can't open $in_file: $!";
      %raw_file = map { /(\d{9})$/ => $raw_file{$1} =
      $raw_file{$1} ? $raw_file{$1} . $_ :
      $_ } <RAW>;
      close RAW;
      open (SORTED, ">$sorted_file") || die "Can't open $sorted_file: $!";
      print SORTED "$raw_file{$_}" for sort keys %raw_file;
      close SORTED;

      Charles K. Clarkson

      : When you use the hash it only
      : keeps the first line if you have multiple social security numbers. I need
      : to keep all the lines.
      : Thanks,
      : Denny Malloy
    Your message has been successfully submitted and would be delivered to recipients shortly.