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