What have you tried? It's hard to give guidance if we don't know where you are coming from and where your issues lie.

As your input file looks a lot like a variant on CSV (with spaces and newlines as delimiters), I would suggest using one of the modules for parsing these types of files off of . My usual choice is Text::CSV, but the search results for CSV will give you an idea of how many solutions are out there for this parsing problem. The above module will generate an array of arrays for you - let us know if you have difficulty dealing with Perl references.

Your code may end up looking something like this (adapted from the documentation):

#!/usr/bin/perl use strict; use warnings; use Text::CSV; my @result; my $csv = Text::CSV->new ( { sep_char => ' ' } ) # should set binary +attribute. or die "Cannot use CSV: ".Text::CSV->error_diag (); open my $fh, "<", "test.csv" or die "test.csv: $!"; while ( my $row = $csv->getline( $fh ) ) { if ($row->[0] =~ m{\QHWUSI-EAS95L_0025_FC:3:1:5232:1082#0/\E}) { if (@result) { $result[1] = $row->[3]; } else { $result[0] = $row->[2]; } } } printf "%s\t%s\n", @result; $csv->eof or $csv->error_diag(); close $fh;

As you did not wrap your input text in <code> tags, it's possible the files were mangled during posting. For example, if your file is actually tab delimited, you would need to specify "\t" as your delimiter, not " ".

Update: Fixed typo in code


In reply to Re: compare lines within a file by kennethk
in thread compare lines within a file by garyboyd

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.