LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-03-2011, 10:19 AM   #1
pepepapa82
LQ Newbie
 
Registered: Oct 2011
Posts: 1

Rep: Reputation: Disabled
Script for parsing a log file


hi,
I'm trying to do a bash script, but i'm not really going good..


I have a log file that has a lot of these with different job ids:

Code:
theserver.log:2011-09-29 10:06:26,210 INFO  [Class] Registering the start of job thejobName of group thejobGroup[jobId=2d1bb3dfe2d4f2a954f574e6f8855004]
theserver.log:2011-09-29 17:52:15,235 INFO  [Class] Registering the finish of job thejobName of group thejobGroup[jobId=2d1bb3dfe2d4f2a954f574e6f8855004] : SUCCESS

I'm doing this to separate all log lines by jobs.. my intention is to change the grep line to generate some other output, something like "DATE TIME - Finish|start - SUCCESS|FAIL" for each job, but i'm currently getting a weird result, it's like the grep works only for the first job, i think perhaps the $job is not being renewed in each loop.

Code:
 while read inputLine
    do
        job=`sed 's/^.*jobId=//' | cut -d ']' -f1`;
        
        echo "grep result for $job:\n"$
        grep -i $job $logFile$
        echo "======================"$
    done < $logFile
thanks in advanced!
 
Old 10-03-2011, 10:55 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Hi,

The line you read is stored in inputLine, which you do not use in the loop itself.

Hope this gets you going again.
 
Old 10-03-2011, 02:26 PM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,245

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
May I also suggest you consider what will be stored in $job prior to running grep??
 
Old 10-04-2011, 02:24 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Also see this page for some hints on doing various string manipulations in-shell. You can probably avoid having to run the external sed and cut processes.

http://mywiki.wooledge.org/BashFAQ/100
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
mail log parsing script in need of makeover puka Programming 2 05-31-2011 11:22 PM
Perl: Parsing a log file MKSrivastava Programming 3 11-10-2010 09:59 AM
Parsing a log file jpostma Linux - Newbie 5 12-05-2008 04:58 PM
Help on parsing a log file in BASH globemast Programming 5 01-11-2007 02:56 AM


All times are GMT -5. The time now is 04:16 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration