LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-13-2004, 10:52 PM   #1
antony_csf
Member
 
Registered: Jun 2004
Posts: 51

Rep: Reputation: 15
Unhappy php question - how to extract line number ??


Dear all,

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
=====================================================

HealthIndexPrinter.java:10:
HealthIndexPrinter.java:11:

how can i extract the 10, 11

I am a newbie on preg_match function??

I read the php.net ref but the example is very complicated.

would anybody expert on it?? would anybody can give me simple example related on my situation??

thx for help!!
 
Old 09-14-2004, 02:29 AM   #2
Mega Man X
LQ Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 65
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...

Regards!
 
Old 09-14-2004, 09:56 PM   #3
antony_csf
Member
 
Registered: Jun 2004
Posts: 51

Original Poster
Rep: Reputation: 15
Smile

Use php function to extract error log line number from file

thx~~! not debug the java program !! sorry for not clear

Last edited by antony_csf; 09-14-2004 at 09:58 PM.
 
Old 09-15-2004, 04:06 AM   #4
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 244Reputation: 244Reputation: 244
Try :

PHP Code:
$count 0;
$file "/path/to/your/log";

// 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($fp4096);
    if(
in_array($count$lines_num)) {
        
//do want you want with this line
        
echo "$line<br>";
    }
    
$count++;
}
fclose($fp); 

Last edited by Cedrik; 09-15-2004 at 04:07 AM.
 
Old 09-15-2004, 11:00 AM   #5
don_pingu
Member
 
Registered: May 2003
Distribution: slackware-current
Posts: 34

Rep: Reputation: 15
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 (:).
 
Old 09-15-2004, 08:08 PM   #6
antony_csf
Member
 
Registered: Jun 2004
Posts: 51

Original Poster
Rep: Reputation: 15
thx~~! all of you!!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sed to extract multiple matches in a line? mhoch3 Linux - Software 8 08-01-2005 03:32 PM
Command line extract Daunted Linux - Software 2 09-30-2004 05:37 PM
How to run command-line? How to extract RPM? How to install SAMBA? azmadar Linux - Newbie 7 09-09-2004 05:18 AM
"how do I extract a number from a text file using shell command?" sdandeker Linux - Networking 3 02-12-2004 08:54 AM
How to extract a part of a line by sed? J_Szucs Programming 2 02-15-2003 06:49 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration