ashok has asked for the wisdom of the Perl Monks concerning the following question:
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.
Another file endno2.c/* file name is endno1.c */ * should*/ int i; 10002 /*should not*/ int j; /*should not*/ int k; /* should*/ int m; 20002
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:int i; int j; /* 10th line = 20 */ int k; /*should*/ int m; 20005
but it prints like thisfind . -name "*.c" -exec cat {} \; |perl -ne 'print $1\n" if $_ =~ /(. +*)\d+$/'
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/*should*/ int m; 2000 /* should*/ int i; 1000 /* should*/ int m; 2000
But it does not print anything. If I remove the $ in the end, then it prints this line also which I do not want.find . -name "*.c" -exec cat {} \; |perl -ne 'print $1\n" if $_ =~ /(. +*)(.*?(?=\d))$/'
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/* 10th line = 2 */
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: regular expression
by archon (Monk) on Feb 28, 2001 at 10:29 UTC | |
by Anonymous Monk on Feb 28, 2001 at 11:30 UTC | |
by tadman (Prior) on Feb 28, 2001 at 20:08 UTC | |
|
Re: regular expression
by ariels (Curate) on Feb 28, 2001 at 13:38 UTC | |
|
Re: regular expression
by mirod (Canon) on Feb 28, 2001 at 12:38 UTC | |
|
Re: regular expression
by pileswasp (Monk) on Feb 28, 2001 at 15:45 UTC | |
|
Re: regular expression
by McD (Chaplain) on Mar 01, 2001 at 00:00 UTC | |
|
Re: regular expression
by Anonymous Monk on Feb 28, 2001 at 23:16 UTC |