![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
|||||
|
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
$
|
|
||||
|
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
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|