Sponsored Content
Top Forums Shell Programming and Scripting Getting previous hour in formatted form Post 302511119 by Amutha on Wednesday 6th of April 2011 03:05:22 AM
Old 04-06-2011
Quote:
Originally Posted by methyl
Why is the parameter value "6" ?
Do you mean:
Please list all the files you would expect to search when the parameter is value "6".

yes what you meant is rite. i need to get the list like this. the duration might be different and the date also might be different depending upon the user is passing it.

---------- Post updated 04-06-11 at 02:05 AM ---------- Previous update was 04-05-11 at 11:34 PM ----------

Quote:
Originally Posted by Chubler_XL
If you have GNU date (accepts -d), this should do it.

Convert date+time to epoch time using %s format (seconds past epoch date).
Once you have the date+time as epoch time you can navigate forwards and backwards by just adding or subtracting the number of secs required (eg 3600 for 1 hour).
Use the GNU -d @<epochsecs> parameter to convert back to the display format.

Code:
FMT=$( echo $1 | sed -e 's/\(.*\)-\(.*\)/\1 \2:00/')
SECS=$(date -d "$FMT" +%s)
COUNT=$2
while [ $COUNT -gt 0 ]
do
   echo logfilename.$(date -d "@$SECS" +%Y-%d-%m-%H)
   let SECS=SECS+3600
   let COUNT=COUNT-1
done


Hi Chuble,

Thank you so much.. i got what i need..
 

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Changing Unix form to Microsoft Word form to be able to email it to someone.

Please someone I need information on how to change a Unix form/document into a microsoft word document in order to be emailed to another company. Please help ASAP. Thankyou :confused: (8 Replies)
Discussion started by: Cheraunm
8 Replies

2. UNIX for Dummies Questions & Answers

an hour less in 24 hour system

My program: __________________________________ #!/bin/ksh DAY=`date +%y%m%d` H=`date +%H` M=`date +%M` day=`date +%m/%d/%y` let h=$H-1 echo DAY $DAY echo H $H echo M $M echo day $day echo h $h _____________________________________ My result: (3 Replies)
Discussion started by: bobo
3 Replies

3. Shell Programming and Scripting

Formatted Output

Hi I have the following lines in a file SWPRC000001NOT STATED 1344 SWPRC000001NOT STATED 1362 SWPRC000001NOT STATED 1418 SWPRC000001NOT STATED 1436 SWPRC000001NOT STATED ... (6 Replies)
Discussion started by: dhanamurthy
6 Replies

4. Shell Programming and Scripting

More formatted string

In a large file i need last line of the file but I want ignore first charcter, ignore leading zeros after first character and print the remaining character as such. Is something i can do it by tail or wc? cat test1 .... ...... 8000003687 cat test2 .... ...... 8000538990 o/p 3687 538990 (3 Replies)
Discussion started by: ford2020
3 Replies

5. Shell Programming and Scripting

Show previous hour

date +%Y%m%d%H output : 2011031415 I want to get previous hour like this 2011031414. Any one can help ? (15 Replies)
Discussion started by: alvin0618
15 Replies

6. Shell Programming and Scripting

Transpose Data form Different form

HI Guys, I have data in File A.txt RL03 RL03_A_1 RL03_B_1 RL03_C_1 RL03 -119.8 -119.5 -119.5 RL07 RL07_A_1 RL07_B_1 RL07_C_1 RL07 -119.3 -119.5 -119.5 RL15 RL15_A_1 RL15_C_1 RL15 -120.5 -119.4 RL16... (2 Replies)
Discussion started by: asavaliya
2 Replies

7. Shell Programming and Scripting

Remove x lines form top and y lines form bottom using AWK?

How to remove x lines form top and y lines form bottom. This works, but like awk only cat file | head -n-y | awk 'NR>(x-1)' so remove last 3 lines and 5 firstcat file | head -n-3 | awk 'NR>4' (5 Replies)
Discussion started by: Jotne
5 Replies

8. Shell Programming and Scripting

Remove previous line if next & previous lines have same 4th character.

I want to remove commands having no output. In below text file. bash-3.2$ cat abc_do_it.txt grpg10so>show trunk group all status grpg11so>show trunk group all status grpg12so>show trunk group all status GCPKNYAIGT73IMO 1440 1345 0 0 94 0 0 INSERVICE 93% 0%... (4 Replies)
Discussion started by: Raza Ali
4 Replies

9. Shell Programming and Scripting

How to convert 24 hour time to 12 hour timing?

Hi friends, I want to convert 24 hour timing to 12 hour please help me... my data file looks like this.. 13-Nov-2011 13:27:36 15.32044 72.68502 13-Nov-2011 12:08:31 15.31291 72.69807 16-Nov-2011 01:16:54 15.30844 72.74028 15-Nov-2011 20:09:25 15.35096 ... (13 Replies)
Discussion started by: nex_asp
13 Replies
DATETIME.SETTIME(3)							 1						       DATETIME.SETTIME(3)

DateTime::setTime - Sets the time

       Object oriented style

SYNOPSIS
public DateTime DateTime::setTime (int $hour, int $minute, [int $second]) DESCRIPTION
Procedural style DateTime date_time_set (DateTime $object, int $hour, int $minute, [int $second]) Resets the current time of the DateTime object to a different time. PARAMETERS
o $object -Procedural style only: A DateTime object returned by date_create(3). The function modifies this object. o $hour - Hour of the time. o $minute - Minute of the time. o $second - Second of the time. RETURN VALUES
Returns the DateTime object for method chaining or FALSE on failure. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.3.0 | | | | | | | Changed the return value on success from NULL to | | | DateTime. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 DateTime.setTime(3) example Object oriented style <?php $date = new DateTime('2001-01-01'); $date->setTime(14, 55); echo $date->format('Y-m-d H:i:s') . " "; $date->setTime(14, 55, 24); echo $date->format('Y-m-d H:i:s') . " "; ?> Procedural style <?php $date = date_create('2001-01-01'); date_time_set($date, 14, 55); echo date_format($date, 'Y-m-d H:i:s') . " "; date_time_set($date, 14, 55, 24); echo date_format($date, 'Y-m-d H:i:s') . " "; ?> The above examples will output something similar to: 2001-01-01 14:55:00 2001-01-01 14:55:24 Example #2 Values exceeding ranges are added to their parent values <?php $date = new DateTime('2001-01-01'); $date->setTime(14, 55, 24); echo $date->format('Y-m-d H:i:s') . " "; $date->setTime(14, 55, 65); echo $date->format('Y-m-d H:i:s') . " "; $date->setTime(14, 65, 24); echo $date->format('Y-m-d H:i:s') . " "; $date->setTime(25, 55, 24); echo $date->format('Y-m-d H:i:s') . " "; ?> The above example will output: 2001-01-01 14:55:24 2001-01-01 14:56:05 2001-01-01 15:05:24 2001-01-02 01:55:24 SEE ALSO
DateTime.setDate(3), DateTime.setISODate(3). PHP Documentation Group DATETIME.SETTIME(3)
All times are GMT -4. The time now is 05:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy