Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Good afternoon! I am new to this forum. In fact this is my first post. I am querying a database and then trying to join the data onto a single line that has the same id in the first field. Here is an example of what the beginning date looks like:

9885 10.10.9.48 Room 1105A 9885 10.10.9.48 Jack 1105A--05D 9885 10.10.9.48 org_code B703 9885 10.10.9.48 Building 1268A 114948 10.10.184.0 nasa_nets off 114948 10.10.184.0 blockSecName test name 114948 10.10.184.0 blockTechName brian test 114948 10.10.184.0 blockAdminName test admin 114949 10.10.184.0 blockSecName John G. Smooth 114949 10.10.184.0 blockTechPhone 222-555-1212 114949 10.10.184.0 blockAdminName Lucy P. Wallice 114949 10.10.184.0 blockAdminId 8878787 114949 10.10.184.0 block_name unknown 114949 10.10.184.0 blockSecId 787878 114949 10.10.184.0 blockAdminEmail lucy.p.wallice@google.com 114949 10.10.184.0 blockTechName TEST LAN 114949 10.10.184.0 blockSecPhone 222-555-3232 114949 10.10.184.0 blockTechEmail terCInternal@google.com 114949 10.10.184.0 blockSecEmail John.goody@google.com 114949 10.10.184.0 nasa_nets off

Note that the first field has an ID. the second, third, and fourth may be different. I don't need to keep the first field at all. Here is what I would like the end result to look like:

10.10.9.48|Room=1105A|Jack=1105A--05D|org_code=B703|Building=1268A 10.10.184.0|nasa_nets=off|blockSecName=test name|blockTechName=brian t +est|blockA dminName=test admin|blockSecName=John G. Smooth|blockTechPhone=222-555 +-1212|bloc kAdminName=Lucy P. Wallice|blockAdminId=8878787|block_name=unknown|blo +ckSecId=78 7878|blockAdminEmail=lucy.p.wallice@google.com|blockTechName=TEST LAN| +blockSecPhon e=222-555-3232|blockTechEmail=terCInternal@google.com|blockSecEmail=Jo +hn.good y@google.com|nasa_nets=off

Notice that every line that had the same first field was put on the same line. In fact, I suppose we can just ignore the first field and just use the second field. So now that you know I am least trying, here is what I have tried:

$out_file="/tmp/brian_test.$datestring"; open(IN,"<$TMPCONTLIST") or die "Can't open $TMPCONTLIST!\n"; open(OUT,">$out_file") or die "Can't open $out_file!\n"; while ($line=<IN>) { @fields = split /\t/,$line; $line = join "|", @fields[1,2,3,4]; print OUT $line; print OUT "\n"; } close IN; close OUT;

It is giving me this....just a sample

10.10.9.48|User_POC_Phone|222-555-2322 | 10.10.9.48|Room|1105A | 10.10.9.48|Jack|1105A--05D | 10.10.9.48|org_code|B703 | 10.10.9.48|Building|1268A

Can you please help? Thanks in advance!!!


In reply to split then join based on common value in field by brianjb

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (8)
    As of 2014-12-27 12:57 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (177 votes), past polls