The requirement is, i need to search for the logs for particular duration. The logs are in the format
the time is in 24 hr format that is being appended to the date to the filename.
i need to search a particular filed in the logs for a particular duration, so i have written a script. The script takes two parameters one as start time(only date-time) and duration.
ex: sh script.sh 2011-03-05-20 6
inside the script i need to start searching the filed rite from "logfilename.2011-04-05-20" to "logfilename.2011-04-06-03"
i'm planning to use for loop to generate the dates and append it to the string "logfilename" and process with that filename.
can you please help me out how to navigate the time in both reverse and forward.
Last edited by radoulov; 04-05-2011 at 10:41 AM..
Reason: Code tags, please!
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.
Last edited by Chubler_XL; 04-05-2011 at 01:13 PM..
You would need to convert start date into seconds from 1970, and add to it the duration (converted in seconds)
(could be achieved using GNU date or using printf in ksh93, or maybe also using the Perderabo script , also read this thread)
You have then the ending date in second that you can convert back to a date so you can then scan the logfile and start printing lines as soon as first date has been reached and stop to print as soon as ending date has been reached.
My understanding is 6 stand for 6 hours so that's
from 2011-04-05-20
to 2011-04-06-01 (included)
(so entries raised from 2011-04-05 20:00 until 2011-04-06 01:59 should be displayed)
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.
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)
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)
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)
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)
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)
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)
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)