I have an issue where I need to parse data and sort data based on a string of numbers that starts at character 28, but the number is between 1 and 5 digits. I'm not quite sure where to start with something like that.

Below is a sample of the data

FULL_TRACE,1,1343599221,114,2.0.51.96,1:195.176.255.130:0.42|2:130.59. +36.138:0.95|3:130.59.36.129:0.47|4:213.248.79.189:0.33|5:213.155.133. +214:13.21|6:213.155.133.141:38.21|7:213.248.93.114:13.64|8:0.0.0.0:-1 +.00|9:193.251.128.210:15.88|10:0.0.0.0:-1.00|11:0.0.0.0:-1.00|12:0.0. +0.0:-1.00 FULL_TRACE,2,1343599221,118,2.0.52.77,1:195.176.255.130:0.38|2:130.59. +36.138:0.80|3:130.59.36.129:1.78|4:213.248.79.189:0.31|5:80.91.249.11 +5:11.86|6:80.91.252.254:12.10|7:213.248.77.206:16.36|8:0.0.0.0:-1.00| +9:0.0.0.0:-1.00|10:0.0.0.0:-1.00 FULL_TRACE,3,1343599221,114,2.0.70.40,1:195.176.255.130:0.54|2:130.59. +36.138:0.55|3:130.59.36.129:114.58|4:213.248.79.189:0.46|5:213.155.13 +3.214:11.86|6:80.91.246.225:12.07|7:213.248.93.114:14.85|8:0.0.0.0:-1 +.00|9:0.0.0.0:-1.00|10:0.0.0.0:-1.00 FULL_TRACE,4,1343599221,114,2.0.79.129,1:195.176.255.130:0.58|2:130.59 +.36.138:0.47|3:130.59.36.129:0.43|4:213.248.79.189:0.30|5:80.91.249.1 +15:11.85|6:80.91.246.219:15.89|7:213.248.93.114:13.39|8:0.0.0.0:-1.00 +|9:0.0.0.0:-1.00|10:0.0.0.0:-1.00

In this data set, the number is 114, but could be 1 or 17000.

#!/opt/local/bin/perl -w $file = "trace.csv"; $file1 = "rgextract.txt"; open (FH, "< $file") || die ("Cannot open file!"); while ($line = <FH>) { $line2 = substr $line, 28, 3; print "$line2\n"; if ($line2 =~ /d++/) { open (FH2,">>$file1") || die ("Cannot open file!"); print FH2 "$line\n"; close (FH2); } } close (FH);

Please help


In reply to substring/regex question by rlastinger

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.