![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Custom short cuts not working on JDS | cooldude | SUN Solaris | 1 | 04-28-2008 04:41 PM |
| pdksh cuts off command prompt | cjackson0 | UNIX for Dummies Questions & Answers | 5 | 12-31-2007 03:27 PM |
| Unknown event - daemon mode cuts programs from resources | baranowb | UNIX for Advanced & Expert Users | 1 | 06-24-2007 11:35 PM |
| Slow FTP & SMB | rockboles | UNIX for Dummies Questions & Answers | 4 | 12-11-2005 07:52 PM |
| multiple cuts syntax problem | Gerry405 | UNIX for Dummies Questions & Answers | 12 | 10-31-2005 09:23 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Multiple echos and cuts too slow
Hi guys, hopefully this hasn't been asked before - couldn't see the question anywhere.
I have a large number of timestamps (hh-mm-ss-millisecond) that I need to find the difference between e.g.: 14-11-07-513 14-11-07-644 Now the script that I have just knocked up is horrifically slow, the crux of which is converting the hh, mm, dd into milliseconds: (( TOTALTIMESTART= (`echo $var | cut -d'-' -f4-8 | cut -d'<' -f1 | cut -c1,2` * 3600000) + \ (`echo $var | cut -d'-' -f4-8 | cut -d'<' -f1 | cut -c4,5` * 60000) + \ (`echo $var | cut -d'-' -f4-8 | cut -d'<' -f1 | cut -c7,8` * 1000) + \ (`echo $var | cut -d'-' -f4-8 | cut -d'<' -f1 | cut -c10,11,12`) )) Once done on two values it subtracts them from each other and usese the difference. There is obviously a better way of doing the part above, but I can't think for the life of me what it would be. Any thoughts? |
|
||||
|
Code:
#!/usr/bin/perl
@arr=("14-11-07-513","14-11-07-644");
for($i=0;$i<=$#arr;$i++){
my @tmp=split("-",$arr[$i]);
$brr[$i]=$tmp[0]*3600000+$tmp[1]*3600+$tmp[2]*60+$tmp[3];
print $brr[$i],"--->\n";
}
print $brr[1]-$brr[0];
|
|
||||
|
Hi guys, well I was still having speed problem (albeit it was taking about 10 seconds to process the file instead of 50 seconds - it is a really big file) because both solutions required me to use a cut to fill the variables which obviously slowed it down a fair bit. I did a bit more digging around and thought I would share what I have come up with instead which takes less than 1 second to complete: Code:
while read monkey
do
set x $monkey
TOTALTIMESTART=$(($((${2}*36000000))+$((${3}*60000))+$((${4}*1000))+$5))
TOTALTIMEEND=$(($((${6}*36000000))+$((${7}*60000))+$((${8}*1000))+$9))
(( TIMEVAR=($TOTALTIMEEND-$TOTALTIMESTART) ))
do some stuff
done < $1
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|