latest status of an field in a log file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers latest status of an field in a log file
# 1  
Old 07-15-2004
latest status of an field in a log file

Hi

I have got a log file which is like:

id status
---------------------
12345 status1.true
12345 status2.true
12345 status3.false
12345 status4.true
23452 status5.true
23452 status6.true
23452 status7.false
65243 status9.true
.
.
.
.
.
.
.
and so on

The id field shows the id of an event while as the status field shows
the status of the id to be true or false.
For a particular id I want to know the status as true or false.
The log is sorted by timestamp
Eg. here in my log the status for 12345 would be true
while as the status for 23452 would be false
and for 65243 it would be true.

Right now I have to manually look at the last entry for the
particular id to find it's status.
Is there another way around to do this.

Regards
enc
# 2  
Old 07-15-2004
grep idnum logfile|tail -1

like this...
logfile has
12345 status1.true
12345 status2.true
12345 status3.false
12345 status4.true
23452 status5.true
23452 status6.true
23452 status7.false
65243 status9.true

$ grep 23452 logfile |tail -1

will give you the last occurance of 23452 only - you could further do your testing of true or false by pulling the true or false with awk

$ grep 23452 logfile |tail -1|awk -F. '{print $2}'
# 3  
Old 07-16-2004
Or do it all with awk..

awk -v id=23452 '$1==id{x=$2}END{print x}' logfile
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Monitor and capture the latest entry from the log file

Hi, I want to monitor a log file using tail -f command and search for a specific string on the most recent entry from the file. If the search string matches with the most recent or last line from the file, I want send an email to the people with the message. tail -f service.log|tail -n 1 ... (5 Replies)
Discussion started by: svajhala
5 Replies

2. Shell Programming and Scripting

Selecting latest entry in the log file

Hi there I am trying to write a script where I will need to look for a specific word in the log file and I am aware this can be done by grep for example. As there will be multiple entries for this I want to grep the last one to enter the log... how would I go about this - would I have to use... (5 Replies)
Discussion started by: simpsa27
5 Replies

3. Shell Programming and Scripting

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... (1 Reply)
Discussion started by: Ariean
1 Replies

4. Shell Programming and Scripting

Grep the Content of a LOG File which has latest Date and Time

Hi All, Need a small help. I have a log file which keeps updating for every Minute with multiple number of lines. I just want to grep few properties which has latest Date and Time to it. How do i do it? I wanted to grep a property by name "Reloading cache with a maximum of" from the... (4 Replies)
Discussion started by: nvindraneel
4 Replies

5. 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

6. 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

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

8. Shell Programming and Scripting

Compare dates in a field and print the latest date row

Hi, I need a shell script which should find the latest date in the field of file and print that line only. For eg., I have a file /date.log Name Date Status IBM 06/06/07 close DELL 07/27/07 open DELL 06/07/07 open : : : From... (1 Reply)
Discussion started by: cvkishore
1 Replies

9. 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