The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how do i put a time stamp in a file name jhamm Shell Programming and Scripting 5 01-29-2007 10:00 AM
Date/Time Stamp JimmyFlip UNIX for Dummies Questions & Answers 0 11-14-2006 11:49 PM
capturing the time stamp in desired format pavan_test UNIX for Dummies Questions & Answers 2 09-21-2006 09:17 PM
greping with time stamp arunkumar_mca Shell Programming and Scripting 1 07-28-2006 05:20 AM
capturing the time stamp to get hours pavan_test UNIX for Dummies Questions & Answers 0 07-24-2006 03:31 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-18-2006
pavan_test pavan_test is offline
Registered User
  
 

Join Date: Oct 2005
Posts: 53
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 (permalink)  
Old 07-18-2006
blowtorch's Avatar
blowtorch blowtorch is offline Forum Advisor  
Supporter
  
 

Join Date: Dec 2004
Location: Singapore
Posts: 2,350
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 (permalink)  
Old 07-18-2006
pavan_test pavan_test is offline
Registered User
  
 

Join Date: Oct 2005
Posts: 53
capturing the time stamp

Thanks a lot.

can anyone plz help me

thanks
pavi
  #4 (permalink)  
Old 07-18-2006
Glenn Arndt's Avatar
Glenn Arndt Glenn Arndt is offline Forum Advisor  
Anomalous Lurker
  
 

Join Date: Feb 2006
Location: Indianapolis, IN
Posts: 255
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 (permalink)  
Old 07-18-2006
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,762
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:09 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0