capturing the time stamp


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers capturing the time stamp
# 1  
Old 07-18-2006
capturing the time stamp

Hi All,

I am working on a korn shell script.
i have a file such as:
DS.PETSCO.20060601203514.20060531.ctl_20060717124431

i have 2 problems here.

1) i have to capture the time stamp from
the above file i.e this number 20060717124431.
format of time stamp is YYYYMMDDHHMMSS.

can anyone plz let me know how do i capture the time stamp.

2) the second problem is, i have to calculate the next 27 hours
from the above time stamp.

SAY time in the above timestamp is 12:44:31 so i have to add
27 hours to this time stamp.

Note:when i add 27 hours please note that date also changes.
so i have to echo the new date and time when i add 27 hours
to the exisitng time stamp.

can anyone plx let me know how I do it.

thanks
pavi
# 2  
Old 07-18-2006
Use cut to get the time stamp.
Code:
echo "DS.PETSCO.20060601203514.20060531.ctl_20060717124431"|cut -d_ -f2

A shell script could then help you add the 27 hours to that datestamp... can't help you with that right now, cause I don't have access to a unix box.
# 3  
Old 07-18-2006
capturing the time stamp

Thanks a lot.

can anyone plz help me

thanks
pavi
# 4  
Old 07-18-2006
I would use ksh's built-in pattern matching to get the time stamp, which is everything after the "_":
Code:
$ file=DS.PETSCO.20060601203514.20060531.ctl_20060717124431
$ echo ${file##*_}
20060717124431
$

Calculating 27 hours from the time stamp is another matter, although here's one way to look at it -- 24 hours from the time stamp is going to be the same time, just 1 (or possibly 2) day(s) later, so just add 3 hours. For date arithmetic, see Perderabo's datecalc script.
# 5  
Old 07-18-2006
Code:
#!/bin/ksh
# add 27 hours to a "timestamp"

timestamp=$(echo "DS.PETSCO.20060601203514.20060531.ctl_20060717124431"|cut -d_ -f2 )
perl -e '
        use Time::Local;
        
        $tm="$ARGV[0]";
        $sec=substr($tm,12,2);
        $min=substr($tm,10,2);
        $hr=substr($tm,8,2); 
        $day=substr($tm,6,2);
        $month=substr($tm,4,2);
        $yr=substr($tm,0,4);        
        $epochtm=timelocal($sec,$min,$hr,$day,$month,$yr);
        $hours=$ARGV[1];
        $epochtm=$epochtm + ($hours * 3600);
        $now=localtime $epochtm;
        print "$now", "\n";        
        ' "$timestamp"  27

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Capturing time stamp in file name

I have a file that is created via a perl script where the file is named like so: 01-07-2016_10:17:08. I am running a shell script that needs to take this file and print it. I can capture the date portion fine, but I am unsure how to capture the time stamp, since there will be a difference from what... (1 Reply)
Discussion started by: ldorsey
1 Replies

2. Solaris

System time and Cron time stamp not matching

On Solaris 10 server the system date won't match with the timestamp on files created by a cron jobs, Please help here is what i get when i check for system date infodba-ie10ux014:/tcpdv1_ie10/tcadmin/bin\n\r-> date Tue Apr 24 15:27:43 GMT 2012at same time i executed a cron job, and checked... (4 Replies)
Discussion started by: karghum
4 Replies

3. Shell Programming and Scripting

file time stamp

Hi All, I am facing small problem. i want to print file time stamp on which date file has placed in the server. i have given some code but its not giving the year. any help appreciated. regards rajesh. (4 Replies)
Discussion started by: rajesh_pola
4 Replies

4. Shell Programming and Scripting

How to get time duration between two human readable time stamp in Unix?

Here is two time I have: Jul 12 16:02:01 Jul 13 01:02:01 and how can I do a simple match to get difference between two time which is 09:00:00 Thanks in advance. (3 Replies)
Discussion started by: ford99
3 Replies

5. Shell Programming and Scripting

regarding time stamp

hi everyone i am facing a strange problem here suppose content of my file is a=1,2,3 b=2,3,4 c=4,5,6 time= now the problem is i want to add value in front of time variable and the value should be i format only "HHMMSS" so it should be like this a=1,2,3 b=2,3,4 c=4,5,6... (3 Replies)
Discussion started by: aishsimplesweet
3 Replies

6. UNIX for Dummies Questions & Answers

How to get the next time stamp in perl?

Hi, I have to find the next time stamp in perl. Here is the code. @time = loaltime(time); print "\n Present time: $time:$time:$time \n"; For example if the time is: "12:55:02" after some process the time becomes 1:00:00. How do i check when it becomes 00:00 i.e from "12:55:02... (0 Replies)
Discussion started by: vanitham
0 Replies

7. UNIX for Dummies Questions & Answers

checking time stamp

Hi, I am having a script in which I am again calling a script, but before calling that script I need to perform a time check (say 1 - 2 am i.e. I would be able to call that script if time is between 1:00 am and 2:00 am) but this time stamp needs to be configurable. can anybody suggest me how... (7 Replies)
Discussion started by: Manvar Khan
7 Replies

8. UNIX for Dummies Questions & Answers

capturing the time stamp in desired format

Hello All, I am working on korn shell script.i have 2 questions; 1) I have a file and i am able to capture the arrival time. the arrival time is capturing as 11:30 ls -ltr aaa.bbb.332121312.*.* | awk -F" " '{print $8}' 11:30 my desired output is 113000 can anyone please suggest me... (2 Replies)
Discussion started by: pavan_test
2 Replies

9. Shell Programming and Scripting

greping with time stamp

Hi all, I want to grep a file name with time stamp as 30 minutes how can i??. Ex I will getting outputs in a file every minutes I want to grep it by a time intervals of 30 and show it . Any help will be great ! Thanks, Arun. (1 Reply)
Discussion started by: arunkumar_mca
1 Replies

10. UNIX for Dummies Questions & Answers

capturing the time stamp to get hours

Hi All, I am working on a korn shell script. I have a problem.i am calculating the next 27 hours from the time stamp. say TSTAMP=20060724000000 if i add 27 hours to the above time stamp, i will get 20060724143000 this is the code: YEAR=`echo $TSTAMP | awk... (0 Replies)
Discussion started by: pavan_test
0 Replies
Login or Register to Ask a Question