Dear Monk,
Let me at the risk of being repetitive since you've already gotten advise on this subject try and make things more clear to you.

Consider the following code:

#!/usr/bin/perl -w use strict; my %storage=(); # untested, but should in theory work... my $junk=<DATA>; #get rid of header while(my $line=<DATA>){ chomp($line); # Get rid of newline my ($host,$dist_id,$status)=split(/[\s\n\t]+/,$line); # split on + any whitespace my $storage{$host) = { host=> $host, dist_id => $dist_id, status=> $status }; # Put this into a hash keyed on the two fields we +want to key on } # We never removed the new line character from $junk so... print $junk; # We reclaim this from the trash can foreach my $key(sort keys %storage){ # # Print the remaining record matching the keys printf "%s\t%s\t%s\n",$storage{$key}->{host},$storage{$key}->{dis +t_id},$storage{$key}->{status}; } exit(0); __END__ COMPUTER DISTRIBUTION_ID STATUS 30F-WKS `1781183799.xxxx1' IC--- 30F-WKS `1781183799.xxx11' IC--- ADM34A3F9 `1781183799.41455' IC---

The way this works is you are going to overwrite subsequent records that you read in for the same host in the hash %storage and as a result get the last record in your data set output. Since you said in CB you don't know if your fields are space or tab separated I covered both bases by using the regex /[\s\t\n]+/ in the split callout.

Hope this helps


Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

In reply to Re: File Manipulation - Need Advise! by blue_cowdawg
in thread File Manipulation - Need Advise! by nashkab

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.