Hi acrobat118,

Here's a rough outline of what you'll need:

  1. Read a file and loop over its lines: "Files and I/O" in perlintro (also covers how to write to an output file)
  2. Act only on lines that match a pattern (grep): "Regular expressions" in perlintro
  3. Break a line into columns (awk): split, e.g. my @F = split; splits the current line $_ on whitespace; the first column is then $F[0], second column $F[1], etc.
  4. Operate only on lines that match certain conditions (awk): "Conditional and looping constructs" in perlintro and the section following it "Builtin operators and functions"
  5. Adding the resulting items to an array: push (for a more advanced approach see "arrays of arrays" in perldsc)
  6. Sorting the array: sort and "How do I sort an array by (anything)?" in perlfaq4

Try using this information to write some code, and if you run into trouble feel free to ask here.

Hope this helps,
-- Hauke D

Update: Expanded post slightly.


In reply to Re: Bash script to perl script by haukex
in thread Bash script to perl script by acrobat118

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.