fix a problem in this script

z=9
i=0
h=02
min=55
while [ $i -lt $z ]
do
cat /home/barmecha/test | grep $h:$min >> /home/barmecha/file1
min=`expr $min + 1`
if [ $min -eq 00 ];
then
h=`expr $h + 1`
fi
i=`expr $i + 1`
done

i have a log file with time wise log in it, this script help me to pull out logs of the give time interval...but the problem is that as soon as it comes to log of 59th min it doesnt jump to the next hour..plz check it and give me a solution

I'm not shure if this should solve your problem but the maximum value of $min must be 60. The if statement should looks like:

if [ $min -eq 60 ];
then
  h=`expr $h + 1`
  min=0
fi

Regards

my logs in the file (test) are like this.....
06/26/08:02:54:00 68% 79% 15% 1585860 429604 597756 332576 409324 1205156 499724 442288 2 221144 355136 1 355136 255400 1 255400 273744 2 136872 529948 1 529948 0 0 293032 1 293032 769272 2 384636 294600 1 294600 53% 0 1 0 0 3
06/26/08:02:55:00 68% 79% 15% 1585860 429604 597756 332576 409324 1205156 499724 442288 2 221144 355136 1 355136 255400 1 255400 273744 2 136872 529948 1 529948 0 0 293032 1 293032 769272 2 384636 294600 1 294600 53% 0 1 0 0 3.8
06/26/08:02:56:00 68% 79% 15% 1585860 429604 597756 332576 409324 1205156 499724 442288 2 221144 355136 1 355136 255400 1 255400 273744 2 136872 529948 1 529948 0 0 293032 1 293032 769272 2 384636 294600 1 294600 53% 0 1 0 0 3.2
06/26/08:02:57:00 68% 79% 15% 1585860 429604 597756 332576 409324 1205156 499724 442288 2 221144 355136 1 355136 255400 1 255400 273744 2 136872 529948 1 529948 0 0 293032 1 293032 769272 2 384636 294600 1 294600 53% 0 1 0 0 3.1
06/26/08:02:58:00 68% 79% 15% 1585860 429604 597756 332576 409324 1205156 499724 442288 2 221144 355136 1 355136 255400 1 255400 273744 2 136872 529948 1 529948 0 0 293032 1 293032 769272 2 384636 294600 1 294600 53% 0 1 0 0 3.5
06/26/08:02:59:00 68% 79% 15% 1585860 429604 597756 332576 409324 1205156 499724 442288 2 221144 355136 1 355136 255400 1 255400 273744 2 136872 529948 1 529948 0 0 293032 1 293032 769272 2 384636 294600 1 294600 53% 0 1 0 0 2.7
06/26/08:03:00:00 68% 79% 15% 1585860 429604 597756 332576 409324 1205156 499724 442288 2 221144 355136 1 355136 255400 1 255400 273744 2 136872 529948 1 529948 0 0 293032 1 293032 769272 2 384636 294600 1 294600 53% 0 1 0 0 3.2
06/26/08:03:01:00 68% 79% 15% 1585860 429604 597756 332576 409324 1205156 499724 442288 2 221144 355136 1 355136 255400 1 255400 273744 2 136872 529948 1 529948 0 0 293032 1 293032 769272 2 384636 294600 1 294600 53% 0 1 0 0 3.3
06/26/08:03:02:00 68% 79% 15% 1585860 429604 597756 332576 409324 1205156 499724 442288 2 221144 355136 1 355136 255400 1 255400 273744 2 136872 529948 1 529948 0 0 293032 1 293032 769272 2 384636 294600 1 294600 53% 0 0 0 0 3.4

and even the above given solution doesnt work...

If you want to extract lines within an exact interval between 2 dates/times you might look at one of the date/time calculation examples on this link:

http://www.unix.com/answers-frequently-asked-questions/13785-yesterdays-date-date-arithmetic.html

Otherwise you can simply extract those lines with sed i.e. if you want the lines between 06/26/08:02:55:00 and 06/26/08:03:01:00 you can do something like:

sed -n '/06\/26\/08:02:55/,/06\/26\/08:03:01/p' file >> file1

or:

grep '06/26/08' file | sed -n '/02:55/,/03:01/p' >> file1

Regards

i tried your suggesation in the form of below written script,it executes but wont give any data in the log file...generated...chk it and reply

echo "ENTER THE START TIME FOR THE REQUIRED DATA {as HH:MM:SS}= "
read DATA_ST_TIME
echo "ENTER THE END TIME FOR THE REQUIRED DATA {as HH:MM:SS}= "
read DATA_END_TIME

OUTPUT_FILE=LOG_FILE_"$DATA_ST_TIME"_"$DATA_END_TIME"

sed -n '/04\/04\/08:"$DATA_ST_TIME"/,/04\/04\/08"$DATA_END_TIME"/p' test >> $OUT
PUT_FILE

this time my log file "test" contains following logs:

04/08/08:22:54:00 51% 59% 5% 1981788 936668 649040 1343236 860648 1529948 1310808 1565760 989932 2341624 8 292703 832088 4 208022 103056 2 51528 1031772 4 257943 663108 3 221036 381128 2 190564 1162056 4 290514 803616 2 401808 528080 2 264040 78% 0 0 0 0 2.6
04/08/08:22:55:00 51% 59% 5% 1981788 936668 649040 1343236 860648 1529948 1310808 1565760 989932 2341624 8 292703 832088 4 208022 103056 2 51528 1031772 4 257943 663108 3 221036 381128 2 190564 1162056 4 290514 803616 2 401808 528080 2 264040 78% 0 0 0 0 2.9
04/08/08:22:56:00 51% 59% 5% 1981788 936668 649040 1343236 860648 1529948 1310808 1565760 989932 2341624 8 292703 832088 4 208022 103056 2 51528 1031772 4 257943 663108 3 221036 381128 2 190564 1162056 4 290514 803616 2 401808 528080 2 264040 78% 0 0 0 0 1.9
04/08/08:22:57:00 51% 59% 5% 1981788 936668 649040 1343236 860648 1529948 1310808 1565760 989932 2341624 8 292703 832088 4 208022 103056 2 51528 1031772 4 257943 663108 3 221036 381128 2 190564 1162056 4 290514 803616 2 401808 528080 2 264040 78% 0 0 0 0 3.4
04/08/08:22:58:00 51% 59% 5% 1981788 936668 649040 1343236 860648 1529948 1310808 1565760 989932 2341624 8 292703 832088 4 208022 103056 2 51528 1031772 4 257943 663108 3 221036 381128 2 190564 1162056 4 290514 803616 2 401808 528080 2 264040 78% 0 0 0 0 1.8
04/08/08:22:59:00 51% 59% 5% 1981788 936668 649040 1343236 860648 1529948 1310808 1565760 989932 2341624 8 292703 832088 4 208022 103056 2 51528 1031772 4 257943 663108 3 221036 381128 2 190564 1162056 4 290514 803616 2 401808 528080 2 264040 78% 0 0 0 0 1.8
04/08/08:23:00:01 51% 59% 5% 1981788 936668 649040 1343236 860648 1529948 1310808 1565760 989932 2341624 8 292703 832088 4 208022 103056 2 51528 1031772 4 257943 663108 3 221036 381128 2 190564 1162056 4 290514 803616 2 401808 528080 2 264040 78% 0 0 0 0 2.2
04/08/08:23:01:00 51% 59% 5% 1981532 936668 649040 1343236 860648 1529948 1310808 1565760 989932 2341624 8 292703 832088 4 208022 103056 2 51528 1031772 4 257943 663108 3 221036 381128 2 190564 1162056 4 290514 803616 2 401808 528080 2 264040 78% 0 0 0 0 1.4
04/08/08:23:02:00 51% 59% 5% 1981532 936668 649040 1343236 860648 1529948 1310808 1565760 989932 2341624 8 292703 832088 4 208022 103056 2 51528 1031772 4 257943 663108 3 221036 381128 2 190564 1162056 4 290514 803616 2 401808 528080 2 264040 78% 0 0 0 0 2.2
04/08/08:23:03:00 51% 59% 5% 1981532 936668 649040 1343236 860648 1529948 1310808 1565760 989932 2341624 8 292703 832088 4 208022 103056 2 51528 1031772 4 257943 663108 3 221036 381128 2 190564 1162056 4 290514 803616 2 401808 528080 2 264040 78% 0 0 0 0 3.9

This should work:

sed -n "/04\/04\/08:$DATA_ST_TIME/,/04\/04\/08:$DATA_END_TIME/p" test >> $OUT

Disadvantage is that you have to escape the slashes in sed. You can use the solution with grep and sed instead:

grep '04/04/08' test | sed -n "/$DATA_ST_TIME/,/$DATA_END_TIME/p" >> $OUT

Regards

it doesnt works as i give the input the output file created but i doesnt have any data in it....

regards

I don't understand why it doesn't works, with the logfiles you've posted the code works fine for me. Try to echo the variables, maybe they aren't set properly.

Regards