fix a problem in this script


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting fix a problem in this script
# 1  
Question 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
# 2  
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:

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

Regards
# 3  
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...
# 4  
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:

https://www.unix.com/answers-frequent...rithmetic.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:

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

or:

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

Regards
# 5  
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
# 6  
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
# 7  
This should work:

Code:
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:

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

Regards
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #382
Difficulty: Medium
HP-UX 11i V3 Release B.11.31 is registered as UNIX V7 compliant.
True or False?

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Fix script to get missing information

Gents, Can you please help me to fix the following script in order to get complete data as desired. I am missing some data in output. the complete input file is attached. The script I am using is awk '{\ status=substr($0,91,2)\ ind=substr($0,26,1);\ ... (10 Replies)
Discussion started by: jiam912
10 Replies

2. UNIX for Dummies Questions & Answers

How to fix Python path for some script/app?

Hello, i have: # python -V Python 2.7.6 But original for my CentOS is 2.3 or 2.4 my python folder: /root/python2.7.6 (inside are folders like lib, include, bin, share) I launched app iotop: # iotop -od 6 Traceback (most recent call last): File "/usr/bin/iotop", line 16, in... (3 Replies)
Discussion started by: postcd
3 Replies

3. Shell Programming and Scripting

My script failed and can't fix it ?

Hi , I'd like to give you a little bit idea about my script which is used to get any generated file from remote server using ftp session then organized those file into directories based on their date ( at the end I supposed to have 1 months directories 20130401 20130402 ....20130430 ,... (27 Replies)
Discussion started by: arm
27 Replies

4. Shell Programming and Scripting

How to fix my IMDB Script

Hello, I am using IMDB bot file for my movie site.. But I get this message like this---Parse error: syntax error, unexpected end of file, expecting variable (T_VARIABLE) or ${ (T_DOLLAR_OPEN_CURLY_BRACES) or {$ (T_CURLY_OPEN) in... (2 Replies)
Discussion started by: lg2013
2 Replies

5. UNIX for Dummies Questions & Answers

Please help to fix awk script

Good morning, fellows. I would need to ask for your help in editing my awk script. Here is the original version: BEGIN { printf ("CRYST1 200.000 200.000 200.000 90.00 90.00 90.00 P 1 1\n") maxatoms=1000 natom=0 found_struct = 0 found_bond = 0 } { if( NF == 5 ) { foundff=0 natom++... (9 Replies)
Discussion started by: snysmumrik
9 Replies

6. Windows & DOS: Issues & Discussions

Fix script error (%%n)

Hi, I'm currently tinkering with a script that uses the for command to process all *.gif files in the current folder. I marked the spot where it exits out with an error by adding a "pause" The error message given is: convert.exe: unable to open image `%x': No such file or directory @... (2 Replies)
Discussion started by: pasc
2 Replies

7. Shell Programming and Scripting

how to fix this awk script?

i have a log file while looks like this ++ user_a blabla blabla nas_b blabla user_d this is a user_a junk line another junk line user_c nas_m blabla ++ basically most of the lines contain a "user" keywords, and the rest of the lines do not have "user" at all. So I have the... (17 Replies)
Discussion started by: fedora
17 Replies

8. Shell Programming and Scripting

Problem with Script that writes max lines of a file - Any ideas how to fix?

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx (4 Replies)
Discussion started by: mmiller99
4 Replies

9. UNIX for Dummies Questions & Answers

Here's the fix for the SiS 7012/7018 sound problem in Mandrake 8.2

Edit your /etc/modules.conf file to either remove or comment out the two lines : alias sound-slot-0 snd-card-intel8x0 above snd-card-intel8x0 snd-pcm-oss ...and replace them with the following line: alias sound i810_audio ....viola! After saving and rebooting, now I gots da sound!... (0 Replies)
Discussion started by: DownSouthMoe
0 Replies

Featured Tech Videos