cgrep for the most recent 15min output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cgrep for the most recent 15min output
# 1  
Old 10-06-2006
cgrep for the most recent 15min output

I have a history file that recieves all sorts of messages 24 hours a day. I have a script that retreives various messages in the history file. There is an one multi line output that is sent to the history file that comes in every 15 minutes. How do I cgrep for the most recent 15 minute output in the history file? If a timestamp is needed, here is the format: 07:46:03
# 2  
Old 10-06-2006
try this

grep "[0-2][0-4]:[0-5][0-9]:[0-5][0-9]" filename

Ex:

qsaskot on eeiatuc930> cat jjj
sdferrhvnerv
sfsd2007-12-01 12:08:45dfdfd
asdhasjkhasfhshfasdhfasjkhfasjkldhfj
asdfasdf
2003-09-31 23:59:50dfdfdfdf
sdfsf
fgfgfgf2001-01-31 00:00:00
dfjsdfasdhfahhl;ajsdfhjh

qsaskot on eeiatuc930> grep "[0-2][0-4]:[0-5][0-9]:[0-5][0-9]" jjj
sfsd2007-12-01 12:08:45dfdfd
2003-09-31 23:59:50dfdfdfdf
fgfgfgf2001-01-31 00:00:00
justsam
# 3  
Old 10-06-2006
can you show the history file?
# 4  
Old 10-06-2006
Here you go, this is what dat continuous data being dumped into the file looks like: I am trying to cgrep the most recent OP:TGCNT message.


S570-65592 06-10-06 10:31:01 474383 TRFM lansing2
OP TRFC30 HSLS
TIME 10:29:35

SECTION 202: HIGH SPEED LINK SET MEASUREMENTS

SM SET MSGSTRAN MSGSRCVD MOCTTRAN MOCTRCVD SDPDUTRN
1 8 540025 505720 25230816 26527017 539089

SM SET SDPDURTR SDPDURCV SDOCTTRN SDOCTRTR SDOCTRCV
1 8 0 504951 27864628 0 29065792

SM SET PDUSTRAN PDUSRCVD PDUOCTTR PDUOCTRC
1 8 611015 576877 28583752 29785188

S4C0-96731290 06-10-06 10:31:03 474384 MAIPR lansing2
M OP:TGCNT,PRINT; PF

S570-65592 06-10-06 10:31:04 474385 CP lansing2
M OP TGCNT LIST SEGMENT=1 STARTED
TG=1936 SZ=269 OOS=1
TG=1938 SZ=264 OOS=1
S570-65592 06-10-06 10:31:07 474386 CP lansing2
M OP TGCNT LIST CONTAINED 1 SEGMENTS COMPLETED

S570-65592 06-10-06 10:31:11 474387 TRFM lansing2
OP TRFC30 SLS
TIME 10:29:35

SECTION 203: SIGNALING LINK SET MEASUREMENTS
# 5  
Old 10-06-2006
you may try something like this

Code:
hour=`date +%H`
minute=`date +%M`
tot_min=$(( hour * 60 + minute ))
time=15
min_diff=$(( tot_min - time ))
hr=$(( min_diff / 60 ))
min=$(( min_diff % 60 ))

sed -n "/${hr}:${min}:[0-9][0-9]/,$ p" file

# 6  
Old 10-06-2006
Quote:
Originally Posted by jojojmac5
I have a history file that recieves all sorts of messages 24 hours a day. I have a script that retreives various messages in the history file. There is an one multi line output that is sent to the history file that comes in every 15 minutes. How do I cgrep for the most recent 15 minute output in the history file? If a timestamp is needed, here is the format: 07:46:03
since you only want the most recent, why not tail the file for an amount, say tail -50 file, then from that output, get the last entry? if not, tail a bigger number and do the same.. will it work?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Solaris files created within directory in last 15min.

I have a directory on a Solaris box that has 58 files written to it every 15min. They have a non standard date as part of the file name but always have another name with it. I need to check that directory for files created within the last 15min and then port the results to a log file. There are... (5 Replies)
Discussion started by: jlaigo2
5 Replies

2. Shell Programming and Scripting

Recent History

Could some let me know the command used to view the commands that I have entered 2 days ago. I am able to perform a command fc -l but its yielding me only last 10 recent events. I need to know the history of the commands that i have entered 2 days ago. Is there anyway that I can get the information... (5 Replies)
Discussion started by: bobby1015
5 Replies

3. Solaris

Recent file available

Dear, Require a script to check : If the file under /opt/OV/log directory has recent 5 hours(or user defined value) file generated or not If generated then cmd to call : opcmsg a=a o=o msg_grp=OpC msg_text="Log file didn't generated on $time" s=critical (1 Reply)
Discussion started by: mjoshi87
1 Replies

4. Shell Programming and Scripting

Need the date now + 15min

Hello all, How can I get a timestamp with 15 min more than current time ? I want to get it like YYYYMMDD-HHMMSS Thank you for your answers :b: Regards (3 Replies)
Discussion started by: Goldorakk
3 Replies

5. Shell Programming and Scripting

Getting the most recent file

Hi people, Please some help over here. I have logs in a directory, in which I need to get the most recent file in order to put it within other command. The format of the files are loadfiles20090308094339_41 loadfiles20090308094418_42 loadfiles20090308095457_43... (4 Replies)
Discussion started by: cgkmal
4 Replies

6. Shell Programming and Scripting

how to get the most recent date value

I have a set of values like this and sometimes more source5local_02Dec2008 source5local_01Nov2008 source5local_05Sep2008 I need to retrieve the string with the most recent date if I cut the date value from each of these strings is there any means to compare them (3 Replies)
Discussion started by: codeman007
3 Replies

7. Shell Programming and Scripting

To keep only the most recent files

Hi all, I'm running on a Sun Solaris machine. I would only want to keep the last 2 most recent files on 1 of my directory. Below shows my script, but it is incomplete. For the ?? part I do not know how to continue. please help:confused: DIR=/tmp/abc OUTPUT=/tmp/output.out... (1 Reply)
Discussion started by: *Jess*
1 Replies

8. UNIX for Dummies Questions & Answers

grep, cgrep or something close

Hi, New to this forum. Nice forum and very helpful. Quick question. I'm trying to grep a list of numbers from single digit to 3-digit. For example, I have a pool of numbers that contain two specific numbers, 17 and 177. I would like to grep for 17 but not get 177. When using grep, I also... (4 Replies)
Discussion started by: dejit
4 Replies

9. Shell Programming and Scripting

getting the most recent file

Hi, I have files coming in every day with that days timestamp like: nameyyyymmddhhmmss.ext. I need the most recent one and so i am using cat `ls -t name*|head -1 ` > temp i am sorting the files in the decending order and am copying the most recent one into a temp file. It works at times... (3 Replies)
Discussion started by: anujairaj
3 Replies

10. Post Here to Contact Site Administrators and Moderators

Recent Changes To Forum ...

Hi all, Have noticed that changes have been made to the forum's main page. The number of new posts/threads is no longer active/visible. Is this a tempoary amendment or a permanent one? Whilst I can not speak for all, I actually refered to the missing line each time I logged on. (2 Replies)
Discussion started by: Cameron
2 Replies
Login or Register to Ask a Question