ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a problem on extract all the line numbers from a java error log
=====================================================
/var/www/html/onJava/modules/onlineide/studentData/s1234567/java/S1T1/HealthIndexPrinter.java:10: not a statement
int;
^
/var/www/html/onJava/modules/onlineide/studentData/s1234567/java/S1T1/HealthIndexPrinter.java:11: 'try' without 'catch' or 'finally'
try{}
^
2 errors
=====================================================
I did not understand your question at all. You are asking to help with PHP, yet you posted error messages of Java and asks to remove the lines?. For what I understand, line 10 and 11 have errors, programming errors and for what I understand, they are:
Line 10 = you've only the datatype int. Datatypes are followed by datatype + name, e.g: int someInt;
Line 11 = you are using try without catch statment. Usually, you've to:
try {
do this;
do this method;
do this method;
} catch (Exception Type1 e){
// do whatever
}
and that's what you are nothing doing correctly. Unless you provide some real source code for us to debug, and explain what you are actually trying to do, it will be very difficult to help you...
// list of numbered line that you want $lines_num = Array(10,11);
$fp = fopen($file, "r") or die("can't open $file to read");
while (!feof($fp)) { $line = fgets($fp, 4096); if(in_array($count, $lines_num)) { //do want you want with this line echo "$line<br>"; } $count++; } fclose($fp);
I assume you want to know on which lines the errors occured?
Take a look at this snippet
Code:
$line = "blabla blabla:didimentionblah.java:134:failure blah";
$matches = array();
if ( preg_match ( "/:([0-9]+):/", $line, $matches ) ) {
echo "Line number: " . $matches[1] . "\n"; // Line number found
} else {
echo "No line number found\n"; // No line number found
}
This will output:
Line number: 134
You can use this in a loop for every line there is.
The preg_match simply looks for any set of numerical characters placed between two semicolons (:).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.