LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Script for parsing a log file (https://www.linuxquestions.org/questions/linux-newbie-8/script-for-parsing-a-log-file-906192/)

pepepapa82 10-03-2011 09:19 AM

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!

druuna 10-03-2011 09:55 AM

Hi,

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

Hope this gets you going again.

grail 10-03-2011 01:26 PM

May I also suggest you consider what will be stored in $job prior to running grep??

David the H. 10-04-2011 01:24 AM

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


All times are GMT -5. The time now is 06:54 AM.