I want to make my code generic, such that it takes all keys(ID1,ID2,ID3...) in key.txt and print the way I printed above.
(The hierarchy of KEY is as the order in key.txt)
i.e.
for loop for ID1
{
for loop for ID2
{
for loop for ID3
{ ... }
}
}
$ ls /temp
one three two
$ cat one
1
2
3
$ cat two
4
5
$ cat three
6
7
8
$ cat comb.sh
for i1 in `cat one`
do
for i2 in `cat two`
do
for i3 in `cat three`
do
echo "$i1|$i2|$i3"
done
done
done
$ ./comb.sh
1|4|6
1|4|7
1|4|8
1|5|6
1|5|7
1|5|8
2|4|6
2|4|7
2|4|8
2|5|6
2|5|7
2|5|8
3|4|6
3|4|7
3|4|8
3|5|6
3|5|7
3|5|8
But above code is hard-coded (I am specifying the file names in the code, I don't want to do that). what I want is that suppose if I add one more file called "four" with entries
$ cat four
9
Without adding a "for loop" for file "four", it should take automatically:
i.e. How to construct the above "for loops" automatically based upon the files in /temp;; (Assuming the order of the loops is defined in a separate file)
sed '1d;$d' a | awk 'BEGIN{FS="|"}{print $2}'> a.t
sed '1d;$d' b | awk 'BEGIN{FS="|"}{print $2}'> b.t
while read aline
do
while read bline
do
echo $aline"|"$bline
done < b.t
done < a.t
rm a.t b.t