the program too slow there is any solution?


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
# 1  
the program too slow there is any solution?

i want to make match between two file:
the first about 1000 records
and the second about 67000 records
I used the nested loop for that the program is two slow
how can i fast this the program

ex:
more file1|while read i
do
more file2|while read x
do
if $parameter1=$parameter2
then .....
fi
done
done
# 2  
(a) sort the files first, change your algorithm

(b) write the program in C or Perl

shell scripts are *really* bad languages for intensive processing.
# 3  
the sort is impossible
and my knowledge of c and perl is weak

con you show me an exable in c
# 4  
Code:
FILE *fp1=fopen("file1.txt","r");
FILE *fp2=fopen("file2.txt","r");
char buf1[256];
char buf2[256];

while (fgets(buf1,sizeof(buf1),fp1))
{
     frewind(fp2);

     while (fgets(buf2,sizeof(buf2),fp2))
     {
            .......
     }
}

# 5  
thanks porter
# 6  
There is no such thing as unsortable data. If you can compare the keys, you can sort them. But I would read the 1000 record file into an array. Then read the 2nd file and compare to the elements of the array.
# 7  
awk is designed to do this using what are called associative arrays.
If you post sample data, say 5 from the small file and 20 from the big, we can give you an example.
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 #320
Difficulty: Medium
Intel created the first consumer 64-bit processor.
True or False?

3 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Calling compiled C program with Perl program

Long story short: I'm working inside of a Unix SSH under a bash shell. I have to code a C program that generates a random number. Then I have to call the compiled C program with a Perl program to run the C program 20 times and put all the generated random #s into a text file, then print that text... (1 Reply)
Discussion started by: jdkirby
1 Replies

2. Shell Programming and Scripting

Please can you help me find a solution in this program in unix ?

Write shell script to read 3 numbers and print them in revers and print wither they are polyndrome numbers or not ????? (2 Replies)
Discussion started by: lovelorn_mn
2 Replies

3. UNIX for Dummies Questions & Answers

Script to open program and send/execute command in program

Hi, i want to write a script that executes a program (exec?) . this program then requires a filename as input. how do i give it this input in the script so the program will be complete run and close by the script. e.g. exec prog.exe program then asks for filename "enter filename:"... (1 Reply)
Discussion started by: tuathan
1 Replies

Featured Tech Videos