I have a file "ingredients.txt" that has a list of 38 words (one per each line). I have figured out how to read it into an array
getArray() { array=() while IFS= read -r line do array+=("$line") done < "$1" } getArray "ingredients.txt"
But now how to get output of all combinations of exactly 4 words from the list of 38?
EDIT: To respond to a comment, I do mean combinations and not permutations, and repetitions are not valid. Four unique words in each combination.
To further clarify, think of it as drawing four marbles of 38 different colors from a bag. No two colors alike. Once you draw a red one, it is impossible to draw another red one for that combination. You draw four, write down the colors, and put them back in the bag, and draw another four. If you get {blue, yellow, purple, red} and {yellow, purple, red, blue} they are not counted separately. I just want combinations, not permutations.
Also, I want each combination printed (going back to the ingredients list): onion, cheese, meat, bun lettuce, carrot, celery, radish carrot, lettuce, celery, vinegar etc.
I hope this is clear.
bash
.mapfile
command to get the file into an array:mapfile -t array < ingredients.txt