Parsing log file and print latest number in loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Parsing log file and print latest number in loop
# 1  
Old 05-15-2014
Parsing log file and print latest number in loop

Hello All,
I have an awk script which parses my log file and prints number grepping from a specific line/pattern, now i have to come with a shell script to continue reading the log untill the job is completed, which i would know while reading session log untill process encounters a final line/statement as shown in the IF LOOP of my below shell script, encountering that line shell script should exit. so while reading this log file this awk script should be executed on the same log file to print latest number only, say my awk script output is as shown below

awk '$1 ~ "^WRITER_" {p=1;next} p&&/X_fc_Loan/{p++;next}; p==2 && NF>=6 && $6 !~/[^0-9]/{print $6;p=0}' s_GenerateXMLDataFile.log

Code:
27213
62087
62087
62090

it should print only the last number 62090, as this number keeps incrementing while job is running. Please find attached log file also.


Algorithm of the shell Script(needs to be tweaked):

Code:
#!/bin/bash

while read line
do
	for i in `awk '$1 ~ "^WRITER_" {p=1;next} p&&/X_fc_Loan/{p++;next}; p==2 && NF>=6 && $6 !~/[^0-9]/{print $6;p=0}' s_GenerateXMLDataFile.log`
	do
		echo max($i)
	done

STRING=`echo $line | awk '{print $2" "$3" "$4" "$5}'`


if [ $STRING = "TM_6020 Session [s_GenerateXMLDataFile] completed" ]
then
	exit 1
fi

done < s_GenerateXMLDataFile.log

Thank you.

Last edited by Ariean; 05-15-2014 at 12:40 PM..
# 2  
Old 05-16-2014
Not sure I grasp what you want to tell us, but to get at the very last of your numbers, don't print $6, but assign it to a variable which then you print in the END section.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parsing a control file loop

Hi, Let's say I have a control file like this: RHEL apple "echo apple" RHEL bravo "ls -l bravo*" RHEL church "chmod church.txt" SUSE drive "chown user1 drive.txt" SUSE eagle "echo "eagle flies"" SUSE feather "ls -l feather*" HP-UX google "sed 's/^Google.*$/&\ ACTION: go to... (14 Replies)
Discussion started by: The Gamemaster
14 Replies

2. UNIX for Dummies Questions & Answers

Help on parsing Oracle RMAN output for string and print sections of a file

Hi, I need some advise on how to print 'sections' of the attached file. I am searching for some that says Marked Corrupt and print some lines after it. At the moment I am running the command below: sed -n -e '/Marked Corrupt/{N;N;p;}' rman_list_validate.txtThis gives me the following... (1 Reply)
Discussion started by: newbie_01
1 Replies

3. Shell Programming and Scripting

parsing characters and number from a big file with brackets

I have a big file with many brackets () in it from which I need to parse number characters and numbers. Below is an example of my file 14 (((A__0:0.02,B__1:0.3)0:0.04,C__0:0.025)2:0.01),(D__0:0.00978,E__2:0.01031)1:0.00362; 15... (1 Reply)
Discussion started by: Lucky Ali
1 Replies

4. Shell Programming and Scripting

Perl's buffered I/O is causing me to miss latest log file entries in log colorizer. How to fix?

I've been finding myself using a log file colorizer written in perl to reformat and colorize the output from many different programs. Mainly, however, I use it to make the output from "tail -f" commands more readable. The base perl script I use is based on "colorlogs.pl" available from the... (1 Reply)
Discussion started by: rcsteiner
1 Replies

5. Shell Programming and Scripting

parsing a file name and add a number

Hi, I have a file po8282.fmt998.fbi.mopac.x.macs.btt.txt . I want to parse the first field which is separated by "." and then find the number and add 1 to it. here is what I am doing to get the first field, but not sure how to only pick the number and add 1 to it... (5 Replies)
Discussion started by: rudoraj
5 Replies

6. Shell Programming and Scripting

print number pyramid with for loop in unix

How can I print number pyramid with for loop(not while only for) in unix like: 1 22 333 4444 55555 ---------- Post updated at 09:09 AM ---------- Previous update was at 09:07 AM ---------- I forgot it is in ksh...I wrote a script in bash but it is nt wrkng in ksh... bash script... (12 Replies)
Discussion started by: joshilalit2004
12 Replies

7. Shell Programming and Scripting

how can i pick the latest log file as per below

in the below .. i want to pick the latest logfile which is having JPS.PR inside.. that means i want particularly "spgport040408041223.log:@@@@@@@@ 04:13:09 Adding: JPS.PR." which is latest among these.. is it possible to compare the current time with logfile time ? reptm@xblr0758rop>... (4 Replies)
Discussion started by: mail2sant
4 Replies

8. Shell Programming and Scripting

search latest version of log file

Have checked the forums and couldnt locate help on this. I want to grep a log file for a pattern using a script - I need to grep the latest log file and not sure how I am able to ensure I am greping the latest log file. Here is sample of log files for yestersday and I effectively need to grep... (10 Replies)
Discussion started by: frustrated1
10 Replies

9. Shell Programming and Scripting

Loop through files in dir, omit file with latest date

I want to loop through files in a directory but omit the file with the latest date in my list of files. How would I accomplish this? Thanks (2 Replies)
Discussion started by: stringzz
2 Replies

10. UNIX for Dummies Questions & Answers

want to cat the latest log file created

everytime a new logfile get created at certain interval of time and i want a simple shell script program which cat the lastest log file when manually excuted (1 Reply)
Discussion started by: vkandati
1 Replies
Login or Register to Ask a Question