|
|
|
|
|
|
| Author |
Message |
pawan_test *nix forums beginner
Joined: 04 Oct 2005
Posts: 38
|
Posted: Tue Jul 18, 2006 2:54 pm Post subject:
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 |
|
| Back to top |
|
 |
Chris F.A. Johnson *nix forums Guru
Joined: 20 Feb 2005
Posts: 2268
|
Posted: Tue Jul 18, 2006 3:45 pm Post subject:
Re: capturing the time stamp
|
|
|
On 2006-07-18, pawan_test wrote:
| Quote: | 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.
|
file=DS.PETSCO.20060601203514.20060531.ctl_20060717124431
timestamp=${file##*_}
| Quote: | 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.
|
newhour=$(( $hour + 27 ))
day_increment=$(( $day + $newhour / 24 ))
For date arithmetic, use GNU date, or see the c.u.s FAQ,
<http://home.comcast.net/~j.p.h/cus-faq.html#6>, or chapter 8 of
my book (that chapter is on line).
--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence |
|
| Back to top |
|
 |
Glenn Jackman *nix forums addict
Joined: 19 Apr 2005
Posts: 97
|
Posted: Tue Jul 18, 2006 6:27 pm Post subject:
Re: capturing the time stamp
|
|
|
At 2006-07-18 10:54AM, pawan_test <sridhara007@gmail.com> wrote:
| Quote: | i have a file such as:
DS.PETSCO.20060601203514.20060531.ctl_20060717124431
1) i have to capture the time stamp from
the above file i.e this number 20060717124431.
format of time stamp is YYYYMMDDHHMMSS.
|
As mentioned,
f=DS.PETSCO.20060601203514.20060531.ctl_20060717124431
timestamp="${f##*_}"
| Quote: | 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.
|
Tcl is good for datetime manipulation.
tclscript='
scan '"$timestamp"' {%4d%2d%2d%2d%2d%2d} Y m d H M S
set time [clock scan "$H:$M:$S $m/$d/$Y"]
set time_27 [clock scan "27 hours" -base $time]
puts [clock format $time_27 -format "%Y%m%d%H%M%S"]
'
new_timestamp=`echo "$tclscript" | tclsh`
--
Glenn Jackman
Ulterior Designer |
|
| Back to top |
|
 |
Google
|
|
| Back to top |
|
 |
|
|
The time now is Mon Dec 01, 2008 9:46 pm | All times are GMT
|
|
Free Hosting Tutorials | Mortgage Loans | Company Reports | Credit Cards | Myspace Backgrounds
|
|
Copyright © 2004-2005 DeniX Solutions SRL
|
|
|
|
Other DeniX Solutions sites:
Unix/Linux blog |
electronics forum |
medicine forum |
science forum |
|
|
Privacy Policy
|
Powered by phpBB © 2001, 2005 phpBB Group
|
|