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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep the Content of a LOG File which has latest Date and Time
# 1  
Old 08-29-2011
Data 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 "123.log" which has some thousands of lines in it

When i use the command "cat 123.log | grep 'Reloading cache with a maximum of' " it fetches the data something like this


"2011-08-29/08:07:44.219 INFO EJB-Timer-0a6c6b1d-563b-4c3a-a756-c854ab44364e[target=jboss.j2ee:ear=ear-xxxx-xxx-xxxxx.ear,jar=xxx-xxxxx-xxx-253134.jar,name= / Reloading cache with a maximum of 10000 loads

2011-08-29/08:08:44.230 INFO EJB-Timer-0a6c6b1d-563b-4c3a-a756-c854ab44364e[target=jboss.j2ee:ear=ear-xxxx-xxx-xxxxx.ear,jar=xxx-xxxxx-xxx-253134.jar,name= / Reloading cache with a maximum of 10000 loads

2011-08-29/08:09:44.242 INFO EJB-Timer-0a6c6b1d-563b-4c3a-a756-c854ab44364e[target=jboss.j2ee:ear=ear-xxxx-xxx-xxxxx.ear,jar=xxx-xxxxx-xxx-253134.jar,name= / Reloading cache with a maximum of 10000 loads "

I always wanted my script to get the last row which has latest date and time in it.


Can someone please HELP its urgent..........
# 2  
Old 08-29-2011
Try using " tail -1 123.log"
# 3  
Old 08-29-2011
The log keeps scrolling and so i can not use the tail -1
# 4  
Old 08-29-2011
What about:
Code:
tail -f Log_File

# 5  
Old 08-30-2011
for last row by property -

Code:
cat 123.log | grep "Reloading cache with a maximum of"|tail -1

---------- Post updated at 05:07 PM ---------- Previous update was at 05:02 PM ----------

another method for latest date -

Code:
export CURRDATE='date +%Y-%m-%d/%H:%M:%S'

cat 123.log|grep $CURRDATE|tail -1

it will show you the last line one which the time CURRDATE was created. you can add some property to get the desired result also.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read latest file name with a date and time and then download from FTP

Hi All, Please help. I have requirement to read the file / folder based on the latest date and download the file and folder. There will be files and folders in the location like 20140630-144422 20140630-144422.csv 20140707-182653 20140707-182653.csv 20140710-183153... (7 Replies)
Discussion started by: Praveen Pandit
7 Replies

2. UNIX for Dummies Questions & Answers

Does 'grep' update a file's access date/time?

I've got a job that finds and removes trace files based upon an access time of more than seven days (I've also tried a modify date). find TABC* -atime +7 -exec rm + find TABC* -mtime +7 -exec rm + Whether I use -atime or -mtime, the process seems to work sporadically. Sometimes it removes... (6 Replies)
Discussion started by: Scottie1954
6 Replies

3. Shell Programming and Scripting

How to extract latest file by looking at date time stamp from a directory?

hi, i have a Archive directory in which files are archived or stored with date and time stamp to prevent over writing. example: there are 5 files s1.txt s2.txt s3.txt s4.txt s5.txt while moving these files to archive directory, date and time stamp is added. of format `date... (9 Replies)
Discussion started by: Little
9 Replies

4. Shell Programming and Scripting

Remove Duplicates on multiple Key Columns and get the Latest Record from Date/Time Column

Hi Experts , we have a CDC file where we need to get the latest record of the Key columns Key Columns will be CDC_FLAG and SRC_PMTN_I and fetch the latest record from the CDC_PRCS_TS Can we do it with a single awk command. Please help.... (3 Replies)
Discussion started by: vijaykodukula
3 Replies

5. Shell Programming and Scripting

Delete log files content older than 30 days and append the lastest date log file date

To delete log files content older than 30 days and append the lastest date log file date in the respective logs I want to write a shell script that deletes all log files content older than 30 days and append the lastest log file date in the respective logs This is my script cd... (2 Replies)
Discussion started by: sreekumarhari
2 Replies

6. Shell Programming and Scripting

grep latest file based on date.

hi all, not sure if this has been posted b4 but i try to search but not valid. this is my question: when i do a ls -ltr there will be a list generated as follows: -rw-r--r-- 1 root sys 923260 Jan 10 04:38 FilePolling.41025.083TL021.xml -rw-r--r-- 1 root sys 1761337 Jan 10 04:40... (12 Replies)
Discussion started by: lweegp
12 Replies

7. Shell Programming and Scripting

grep to show date/time of file the string was found in.

I've seen several examples of grep showing the filename the string was found in, but what I really need is grep to show the file details in long format (like ls -l would). scenario is: grep mobile_number todays_files This will show me the string I'm after & which files they turn up in, but... (2 Replies)
Discussion started by: woodstock
2 Replies

8. Shell Programming and Scripting

shell script to find latest date and time of the files

Hi everyone, Please help:) I have a list of 1000 different files which comes daily to the directory.Some of the files are not coming to the directory now. I need to write a shell script to find the latest date and time of the files they came to the directory. The files should be unique.... (1 Reply)
Discussion started by: karthicss
1 Replies

9. Shell Programming and Scripting

Processing a log file based on date/time input and the date/time on the log file

Hi, I'm trying to accomplish the following and would like some suggestions or possible bash script examples that may work I have a directory that has a list of log files that's periodically dumped from a script that is crontab that are rotated 4 generations. There will be a time stamp that is... (4 Replies)
Discussion started by: primp
4 Replies

10. Shell Programming and Scripting

Date and time log file

Hi, I wrote a small perl script in unix that searches in a file and saves some information in a separate file. Since this is a log file, I would like to have the date added to file name. I have no idea where to start. output: log_010907.txt thanks ken (8 Replies)
Discussion started by: captoro
8 Replies
Login or Register to Ask a Question