Grep with time constraints


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Grep with time constraints
# 1  
Old 01-15-2015
Grep with time constraints

Hello Friends -

I am trying to grep certain messages that have a time slot like this:

Code:
 
MyRate=33FC|SystemDEF=445DE|Calc=33W2|Time=15:50:24

I am trying to grep everything after Time=15:50:26 including SystemDEF=E2S and Calc=33W2 into a file called myrate.dat

Not able to grep everything after the time, can you help?

Thanks again
# 2  
Old 01-15-2015
Not clear. How and where does SystemDEF=E2S come into play? You could use awk like
Code:
awk -F"|" '$4=="Time=15:50:26" {P=1} P' msgfile >myrate.dat

# 3  
Old 01-15-2015
grep does not have less than, greater than, if, then, and, etc. So it's not much use for comparing time.

awk does, though. If your times are in HH:MM:SS format they are easy enough to compare.

If your 'time=' field is always the last field:

Code:
awk '($NF >= ("Time=" TIME))' TIME="15:50:24" filename

This User Gave Thanks to Corona688 For This Post:
# 4  
Old 01-15-2015
Thank you.

I am not attempting to compare time.

However, the file contains many messages as above example, each have a time field with a different time.

RudiC: the file will contain a value called SystemDEF=E2S


Hence, I am trying to get:

1. Any message that came after 15:56:26
2. That also contained the value SystemDEF=E2S
3. And also contained the value Calc=33W2

Hope i am able to make sense!

Thanks
# 5  
Old 01-15-2015
Quote:
Originally Posted by DallasT
1. Any message that came after 15:56:26
2. That also contained the value SystemDEF=E2S
3. And also contained the value Calc=33W2
Code:
awk '!f&&/Time=15:56:26/{f=1;next}f&&/SystemDEF=E2S/&&/Calc=33W2/' file

This User Gave Thanks to Yoda For This Post:
# 6  
Old 01-15-2015
Quote:
Originally Posted by DallasT
Thank you.

I am not attempting to compare time.
. . .
And how do you get at records AFTER that target time? Assuming that records are in increasing time order, try

Code:
awk -F"|" '$4=="Time=15:50:26" {P=1} P && $2 ~ /=E2S$/ && $3 ~/=33W2$/' msgfile >myrate.dat

This User Gave Thanks to RudiC For This Post:
# 7  
Old 01-15-2015
Thank you everyone.

Thanks Yoda, may the force be with you, I have one question:

What if i want to search with same parameters as before but

Time should be between 15:25:20 and 16:33:45
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Solaris

Need help in configuring Password Constraints for Solaris 11.3

Hello Friends I was running Solaris 11.3 x86. Below is my configuration to set password Constraints. more /etc/default/passwd MAXWEEKS=4 MINWEEKS=1 WARNWEEKS=1 PASSLENGTH=8 NAMECHECK=YES HISTORY=4 MINDIFF=3 MINALPHA=2 (4 Replies)
Discussion started by: jebby123
4 Replies

2. Shell Programming and Scripting

Parsing a file based on positional constraints

I have a list file1 like dog cow fox cat fish duck crowI want to classify the elements of file1 based on constrains applied on file2. Additionally the number of elements (words) in the each line of file2 is not fixed. This is my file2 cow cat fox dog cow fox dog fish crow fox dog cat ... (5 Replies)
Discussion started by: sammy777
5 Replies

3. Solaris

Pkg update: No solution was found to satisfy constraints

I have an x86 Solaris box running 11.2 and have run into the following issue when attempting to run a package update. Has anyone else come across this issue and resolved it successfully, or am I waiting on Oracle to release other updated packages? uname -a SunOS <hostname> 5.11 11.2... (13 Replies)
Discussion started by: nova_cyclist
13 Replies

4. UNIX for Advanced & Expert Users

Teradata and Informatica Load constraints

HI Team , I have interesting issue observed when using teradata sql assistant(14.1) and Informatica tool (9.5) versions. I created SQL code in teradata where source count is 5000 records . I am using source and target database as teradata and trying to load using informatica tool . Its straight... (0 Replies)
Discussion started by: Perlbaby
0 Replies

5. Shell Programming and Scripting

grep the time within given minutes

Mar 26 15:25:11 : jdoe : TTY=pts/2 ; PWD=/home/jdoe ; USER=root ; COMMAND=/usr/bin/su - Mar 26 15:28:52 : jdoe : 3 incorrect password attempts ; TTY=pts/2 ; PWD=/home/jdoe ; USER=root ; COMMAND=/usr/bin/su - Mar 25 12:23:07 : jdoe : TTY=pts/2 ; PWD=/home/jdoe ; USER=root ; ... (6 Replies)
Discussion started by: Daniel Gate
6 Replies

6. Homework & Coursework Questions

Grep for modified time

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: is it possible to come up with a list of files that are modified before a certain number of hours only using the... (3 Replies)
Discussion started by: momo.reina
3 Replies

7. Shell Programming and Scripting

Grep for modified time

is it possible to come up with a list of files that are modified before a certain number of hours only using the grep command? ex. list files that were modified less than 10 hours ago i've only managed to list files that were created on the same day, i can't seem to figure out how to work... (3 Replies)
Discussion started by: momo.reina
3 Replies

8. UNIX for Advanced & Expert Users

GZIP memory constraints

Currently I am using the ZLIB_VERSION "1.2.3" . The memory requirement for Zlib/GZIP compression is stated as /* The memory requirements for deflate are (in bytes): (1 << (windowBits+2)) + (1 << (memLevel+9)) that is: 128K for windowBits=15 + 128K for memLevel = 8 (default... (0 Replies)
Discussion started by: Parmod Garg
0 Replies

9. Programming

About template constraints

Hi, i have class template, 1)can i override the copy constructor 2)can we have virtual function in class template if not plz tel why? I tried , compile error comes for me... Thanks Sarwan (0 Replies)
Discussion started by: sarwan
0 Replies
Login or Register to Ask a Question