complicated date stamp pattern


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users complicated date stamp pattern
# 1  
Old 09-17-2010
complicated date stamp pattern

Hi,

I have a log file which contains lines like below:

Code:
2010-07-19 07:13:19,021 ERROR system ...(text)
2010-07-19 07:22:03,427 ERROR system ...(text)
class com... (text)
2010-07-19 07:23:19,026 ERROR system ...(text)
class com... (text)

each line is a separate line... I am given the a
start time such as : "2010 07 17 07 13 19 "
end time such as: "2010 07 19 20 00 00"
and I have 2 variables which puts them to the format of "2010-07-19 07:13:19" and "2010-07-19 20:00:00

I'm not sure what to put such a search pattern to return the log lines in between (inclusive) the start and end times given, and on the example above, it should return lines afters it as well.

if I put the start time and end time of only the first time log line from above it should be:
Code:
2010-07-19 07:13:19,021 ERROR system ...(text)


if I put the start time and end time of only the second time log line from above it should be:
Code:
2010-07-19 07:22:03,427 ERROR system ...(text)
class com... (text)

if I put the start time and end time of only the third time log line from above it should be:
Code:
2010-07-19 07:23:19,026 ERROR system ...(text)
class com... (text)

or if i just put a start and end time including all it should return everything.. etc

This problem is kind of complicated... I would greatly appreciated if anyone can even lead me in the way of getting it to the correct search outputs.

Thanks

I have the following code which, only looks for the start time for exact matches, and returns.
Code:
awk -vs="$sstart" '$0~"^"s{p=1}!($0~"^"s) && /^2010/{if(p==1){print "\n"}p=o}p' "$f"

$sstart is the format of "2010-07-19 07:13:19", and $F is the file name.
# 2  
Old 09-20-2010
Hey you can do it this way:

Inside your shell script, let's say the start daytime and end daytime are variables vstart and vend

then add the following in ur shell script:

Code:
vend=${vend:-vstart}

sed -n -e '/^'"${vstart}"'/,$p
/^'"${vend}"'/ { 
:up
n
/....-..-.. ..:..:../q
p
b up }' <your log file name>

# 3  
Old 09-20-2010
Thanks for helping, but it's still not working the way i want it to be,

the line
Code:
vend=${vend:-vstart}

doesn't seem to do anything, vend is still vend...

---------- Post updated at 12:51 PM ---------- Previous update was at 12:22 PM ----------

Is there any built-in way of getting even a list of the times in between start and end? or do i need to make a function myself to do it specifically?

Thanks
# 4  
Old 09-20-2010
Sorry there is a typo in my code. Please replace it as following:

Code:
vend=${vend:-$vstart} ## I missed a $ there

It works like this: if vend is not set then value of vstart is assigned to it.
# 5  
Old 09-20-2010
Thanks, but... vstart and vend will always be set... and how does that help in finding out the lines in between?
# 6  
Old 09-20-2010
Code:
vend=${vend:-$vstart}

## the following sed script will stop printing when it finds vend in the log file. 
## So I am setting vend to vstart if you are not providing vend with any input value

sed -n -e '/^'"${vstart}"'/,$p
/^'"${vend}"'/ { 
:up
n
/....-..-.. ..:..:../q
p
b up }' <your log file name>

# 7  
Old 09-20-2010
I am always always always providing a vend value,
Quote:
## the following sed script will stop printing when it finds vend in the log file.
this is not what I was looking for at all, but thanks anyways.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Files with date and time stamp

Hi Folks, Need a clarification on files with date and time stamp. Here is my requirement. There is a file created everyday with the following format "file.txt.YYYYMMDDHHMMSS". Now i need to check for this file and if it is available then i need to do some task to the file. I tried... (6 Replies)
Discussion started by: jayadanabalan
6 Replies

2. Shell Programming and Scripting

sed with complicated variable pattern

Hi, Below is the content of the file how it looks: # EMAIL #export BMS_EMAIL_ENABLED=true export BMS_EMAIL_ENABLED=false #export BMS_EMAIL_SERVER=esasmtp01.kohls.com export BMS_EMAIL_SERVER=esasmtp01.kohls.com.SMTP_SERVICE export BMS_EMAIL_FROM_ADDRESS=ec_notify@kohlsectest.com export... (4 Replies)
Discussion started by: pravintse
4 Replies

3. UNIX for Advanced & Expert Users

rsync - date/time stamp

Hi, We are using RSYNC for syncing remote directories and working great. Our requirement is to have the destination files with date/time stamp of when they're copied on to the destination server, NOT the date/time stamps of source files/directories. As RSYNC, by default, preserving the same... (4 Replies)
Discussion started by: prvnrk
4 Replies

4. UNIX for Dummies Questions & Answers

How to Zip the files from date Stamp to end date Stamp

Hi, I need to zip the list of files using from date Stamp to end date Stamp, How can I filter and make FromDate_EndDate.gzip? any idea? (1 Reply)
Discussion started by: redlotus72
1 Replies

5. UNIX for Dummies Questions & Answers

Date/Time Stamp

Hi All, Wondering if there is have a date added at the end of a test string. I have a hypothetical text file day one: John Paul George When the file day one is output, I'd like it to read something like this: John 101406 Paul 101406 George 101406 Day two, when the same text file... (0 Replies)
Discussion started by: JimmyFlip
0 Replies

6. Shell Programming and Scripting

Date Stamp on new file

Dear Gurus, I'm trying to move a number of files from one directory to another directory with a new date stamp. This is my script: #! /bin/csh Today_Date=`date +%Y%M%D` mv /usr/TRS/data/TS* /usr/TRS/backup/TS*.${Today_Date} when i run the script i'm getting the following errors: mv:... (14 Replies)
Discussion started by: lweegp
14 Replies

7. Shell Programming and Scripting

creating a new file with date stamp

Hi, can any one tell me how to achieve this...I will input the path and file name and it should rename it to current date and time... this is what I tried... #! /usr/bin/sh set -x cd /info_stg/vul/Scripts TODAY_DATE_TIME=`date +%Y%m%d%H%M%S` IN_FILE_PATH=`cat file.txt | awk -F, '{... (2 Replies)
Discussion started by: mgirinath
2 Replies

8. Shell Programming and Scripting

Date Stamp -1

I need to move files after midnight but attach the previous date to it. Moving files before midnight no proproblem but how can I move files which are created on the 22nd for example but add a date stamp of previous day? Date ='date +"Y%m%d"' gets today's date but how can I get yesterday's... (3 Replies)
Discussion started by: candle_66
3 Replies

9. Shell Programming and Scripting

Date Time Stamp

I'm trying to write a script that checks the DTS of a file the compares it to the current time. If greater that 60 mins has gone by and the file has not been written to alert. So far I have the time pulled from the file but I dont know how to compare the times against a 60 min difference. ... (2 Replies)
Discussion started by: jarich
2 Replies

10. UNIX for Dummies Questions & Answers

File date and time stamp

I have to capture the creation date and time stamp for a file. The ls command doesn't list all the required information. I need year, month, day, hour, minute and second. Any ideas... (1 Reply)
Discussion started by: Xenon
1 Replies
Login or Register to Ask a Question