#!/usr/bin/env bash # INCOMPLETE set -o errexit set -o nounset set -o pipefail if [[ "${TRACE-0}" == "1" ]]; then set -o xtrace fi INPUT_FILE="$1" gen_maps () { local map_count paragraph_num lines name map_count=$(awk -v RS= 'END {print NR}' "${INPUT_FILE}") map_count=$((map_count-1)) # one paragraph in file is seeds for ((i=1; i<=map_count; i++)); do paragraph_num=$((i+1)) # number of paragraph in input file lines="$(awk -v RS= "{if(NR == ${paragraph_num}) print}" "${INPUT_FILE}"| tail -n +2)" name="$(awk -v RS= "{if(NR == ${paragraph_num}) print}" "${INPUT_FILE}" | head -n 1 | cut -d ' ' -f 1 | tr - _)" declare -n array="${name}" while read -r line; do array+=("${line}") done <<< "${lines}" maps+=("${name}") done } gen_seed_pairs () { local seed_count pair_count i_start i_length start length end IFS=" " read -r -a seeds <<< "$(grep seeds "${INPUT_FILE}" | cut -d ' ' -f 2-)" seed_count="${#seeds[@]}" pair_count=$((seed_count/2)) for ((i=0; i