#!/bin/bash

FILE_RANGE="./temp.txt"
FILE_COUNTRY_CODE="./GeoLite2-Country-CSV_20190806/GeoLite2-Country-Locations-fr.csv"
CODE=0

while read p; do
    CODE=$(awk -F ',' '{print $2}' <<< $p)
    RANGE=$(awk -F ',' '{print $1}' <<< $p)
    COUNTRY=$(awk -v country_code="$CODE" -F ',' '$0 ~ country_code {print $5}' $FILE_COUNTRY_CODE)
    printf "%s\n" "$RANGE" >> ./country/"$COUNTRY".txt
done < temp.txt
