Visit The New, Modern Unix Linux Community


need inputs on how i can change my script to reduce amount of time the script takes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need inputs on how i can change my script to reduce amount of time the script takes
# 1  
need inputs on how i can change my script to reduce amount of time the script takes

HI ,
I have a list1 which consists of data that i have to search and a list2 which has the files that need to be searched .So basically i am using list1 on list2 to see if list1 data is present if found replace it .I have written the code using foreach loop for each list .This is taking the script longer time because the data and the number of files to be search is more....Is there a way i can reduce the time the scripting is takes? I saw somehwere we can use pipe to collect data and doa parallel serach ...but not sure on how to use it

here is teh present code that i have
@list_of_newhier1------------list1
@list_of_newhier-------------list2

foreach $other_list(@list_of_newhier1)
{
chomp(@list_of_newhier1);
if(not ($other_list=~/^\$/) and $other_list=~/\s*(.*).$prefix\.([^\.\t ]+)$/)
{
$other_list=~/\s*(.*).$prefix\.([^\.\t ]+)$\s*/;
$other_list1 = $1;
$other_list2=$2;

foreach $list_of_newhier(@list_of_newhier)
{
chomp(@list_of_newhier);
open(NEWHIER, "$dirname1/$other_list")or die " Can not open $other_list $! \n";
open(NEWHIER1, ">$dirname1/$other_list.tmp")or die " Can not open $other_list.tmp \n";

while(<NEWHIER>)

{


if(/$list_of_newhier/)
{
$_=~s/\b$list_of_newhier\b/$list_of_newhier.$prefix/ ;
}
print NEWHIER1 $_;
}
close(NEWHIER);
close(NEWHIER1);

$sys_err = system("cp $dirname1/$other_list.tmp $dirname1/$other_list");
$sys_err = system(" rm $dirname1/$other_list.tmp");
}
}
}


Thanks
# 2  
For starters...
don't chomp the whole array on every pass through it
don't keep opening and closing the files on each instance of list2

Your model is very confusing - take a good look at the algorithm you've come up with and simplify it.
Store in memory rather than keep opening and closing files and writing to disk.

Hope that helps.

Jerry

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

Test Your Knowledge in Computers #283
Difficulty: Easy
Early computers were built to perform a series of single tasks, like a calculator.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Optimizing script to reduce execution time

AFILENAME=glow.sh FILENAME="/${AFILENAME}" WIDTHA=$(echo ${FILENAME} | wc -c) NTIME=0 RESULTS=$(for eachletter in $(echo ${FILENAME} | fold -w 1) do WIDTHTIMES=$(awk "BEGIN{printf... (5 Replies)
Discussion started by: SkySmart
5 Replies

2. Shell Programming and Scripting

Script to change date/time

Hi everybody! I need to perform a task with a script but I have no idea how to do it, I hope someone could help me: - on my linux pc I have many folders with movies, tv shows, toons, ecc. They are shared by a dlna server to my panasonic tv where I can browse and see them. The problem is that... (6 Replies)
Discussion started by: Torquemada
6 Replies

3. Shell Programming and Scripting

Script which takes two inputs based on that execute othe scripts

Hi, I am using solaris 10 bash shell.this might a small script but i am not much familiar with scripting. My requirement here is script should prompt for users two opions like this "please select either any one option makefile or make& build file". if the user selects make file option... (2 Replies)
Discussion started by: muraliinfy04
2 Replies

4. Shell Programming and Scripting

Need a shell script which takes two inputs and copy the files from one directory to other

Hi, I am using solari 10 OS which is having bash shell. I need a shell script which takes user home directory and name of the file or directory as a input and based on that copy the files accordingly to the other directory. example:I hava a machine1 which is having some files in a... (8 Replies)
Discussion started by: muraliinfy04
8 Replies

5. Shell Programming and Scripting

Automation script to reduce the installation time

DELETED. (0 Replies)
Discussion started by: vasuvv
0 Replies

6. Shell Programming and Scripting

Perl script for taking inputs from one script and storing them into a document.

Hi. I wanted to create a Perl script which can take the outputs of a Perl script as it's input and temporarily store them in a document. Need help. Thanks.:) (8 Replies)
Discussion started by: xtatic
8 Replies

7. Shell Programming and Scripting

Script that takes in variables, and outputs to another text or script file

Ok, I sort of need to create a command files that will be ftped to another server to run. I have some input variable that will need to be read, and then transformed into another script file. Here are some examples. Server 1: outputCmd.sh passing in ./outputCmd.sh nh8oaxt Release_4_0... (1 Reply)
Discussion started by: orozcom
1 Replies

8. UNIX for Dummies Questions & Answers

Help how replace stardard keyboard inputs by arguments at run time of a script

Hello Everybody, Please help. I was trying to automate the use of a third-party given shell script. The script is written to be used at run-time to collect a few variables to be provided by the user through key board, in the fashion as below: ./runcommand please provide a file name to... (6 Replies)
Discussion started by: Dingrong
6 Replies

9. Shell Programming and Scripting

shell script takes long time to complete

Hi all, I wrote this shell script to validate filed numbers for input file. But it take forever to complete validation on a file. The average speed is like 9mins/MB. Can anyone tell me how to improve the performance of a shell script? Thanks (12 Replies)
Discussion started by: ozzman
12 Replies

10. Shell Programming and Scripting

executing a script for a certain amount of time

I am writing a script that takes two parameters: the name of another script and an integer that represents a number of seconds. The script must execute the second script (first parameter) for the specified number of seconds (second parameter), suspend it for the same number of seconds, and continue... (9 Replies)
Discussion started by: ponchorage
9 Replies

Featured Tech Videos