This may get you started.

#! perl -w my $output = ''; while( my $line = <DATA> ) { # get rid of line terminator chomp $line; # Get rid of line numbers $line =~ s/^N[0-9]{2}\ //; # Replace * and the beginning of the line with #(Assumption: No further processing of comments required.) $line =~ s/^\*(.*)/!$1/ and print $line and next if $line; # Keep any numbers prefixed with X,Y or Z. $line =~ s/(X|Y|Z)([0-9.-]+)/ $2/g if $line; # Throw the rest away. $line =~ s/[A-Z][0-9.+-]+//g if $line; print $line; } __DATA__ N38 * TOOL 11: 0.125 DIA. FINISH ENDMILL N39 M6T11 N40 E1 N41 S15000M3M7 N42 G17G90G0G8X-5.58Y-18. N43 Z0.05H11 N44 G82G98X-5.58Y-18.Z-0.2R+0.01P50F100. N45 X-3.171 N46 X-1.025 N47 X0.887 N48 X3.371Y-18.688 N49 Y-17.312 N50 X5.46Y-18.

Output (asked for) followed by actual. I think that you made a mistake in what you asked for. Correct me if I am wrong.

! TOOL 11: 0.125 DIA. FINISH ENDMILL 5.58 -18. 0.05 -5.58 -18. -0.2 1. +025 0.887 3.371 -18.688 -17.312 5.46 -18.

(actual!)

C:\test>182489 ! TOOL 11: 0.125 DIA. FINISH ENDMILL -5.58 -18. 0.05 -5.58 -18. -0.2 - +3.171 -1.025 0.887 3.371 -18.688 -17.312 5.46 -18.

In reply to Re: regular expression help by BrowserUk
in thread regular expression help by airblaine

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.