Edited by mirod: changed the title as suggested.

Hi,
I am trying to print the source line in C/C++ which ends with some numbers. I am receiving C/C++ files ending with some numbers. I can not compile those source. For ex.

/* file name is endno1.c */ * should*/ int i; 10002 /*should not*/ int j; /*should not*/ int k; /* should*/ int m; 20002
Another file endno2.c
int i; int j; /* 10th line = 20 */ int k; /*should*/ int m; 20005
So I am trying to print those lines ending with nos. My code should be in single line. So I came out on unix machine like this:
find . -name "*.c" -exec cat {} \; |perl -ne 'print $1\n" if $_ =~ /(. +*)\d+$/'
but it prints like this
/*should*/ int m; 2000 /* should*/ int i; 1000 /* should*/ int m; 2000
That is it matches entire line except the last character. My intention is to not to print those nos in the end. Then I have modified my code like this
find . -name "*.c" -exec cat {} \; |perl -ne 'print $1\n" if $_ =~ /(. +*)(.*?(?=\d))$/'
But it does not print anything. If I remove the $ in the end, then it prints this line also which I do not want.
/* 10th line = 2 */
Can you pl. correct my regular expression. Again I want it to be in single line. My intention is to compile the code cleanly in C/C++ without those nos in the end. I am redirecting the output to a file and compile then. Thanks Ashok

In reply to Matching lines in a file that end in numbers (was: regular expression) by ashok

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.