Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

create file with possible combinations of numbers from 3 files 1

Status
Not open for further replies.

mpramods

Technical User
Jun 3, 2003
50
US
Suppose I have 2 numbers each in 3 files

file1 contains
100
200

file2 contains
333
444

file3 contains
505
606

How can I create a new file which will have all possible combinations of numbers from the 3 files, pasted side by side?

The new file will contain the following:
100-333-505
100-333-606
100-444-505
100-444-606
200-333-505
200-333-606
200-444-505
200-444-606

Currently, I have more than 8000 numbers in each file. So when I create a new file with the possible combinations from these 3 big files, this process needs to be fast. And because 8000 numbers from 3 files would produce billions of combinations, I need to limit the new file to 10 million numbers.

How can I achieve this?

Thanks,
Pramod
 
not sure how fast this would be - dont have 8000 numbers in 3 files to fully test (and too lazy to create), but... this worked with the following limited files:

file1:
100
200
300

file2:
333
444
555

file3:
505
606
707

Code:
COUNT=0
#LIMIT=10000000
LIMIT=3      #just for testing purposes
while read -r NUM1
do
  while read -r NUM2
  do
    while read -r NUM3
    do
      echo "${NUM1}-${NUM2}-${NUM3}"
      ((COUNT = COUNT + 1))
      if (( COUNT >= $LIMIT))
      then
       exit
      fi
    done < file3
  done < file2
done < file1
 
sbrews,

You rock!! You get a star for the solution.

Your script is working perfect. It took appro 17 minutes to generate the file with 10,000,000 numbers.

Cheers,
Pramod
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top