Skip to content

Instantly share code, notes, and snippets.

@operatehappy-bot
Created October 25, 2019 15:04
Show Gist options
  • Save operatehappy-bot/d13dd09648701c1085a69f628a19f27c to your computer and use it in GitHub Desktop.
Save operatehappy-bot/d13dd09648701c1085a69f628a19f27c to your computer and use it in GitHub Desktop.
Create URL files from CSV

This script transforms a headerless CSV file (containing URL Codes and URLs) into a number of plaintext files named after the URL Code and containining the (actual) URL.

#!/bin/sh
URLS_FILE="urls.csv"
URLS_DIR="urls"
mkdir -p "${URLS_DIR}"
while IFS=, read -r CODE URL
do
if [ -z "${CODE}" ];
then
echo "missing code for item with URL \"${URL}\"}";
else
echo "creating file ${URLS_DIR}/${CODE} for ${URL}";
echo "${URL}" > "${URLS_DIR}/${CODE}"
fi
done < "${URLS_FILE}"
2BkX2OA https://example.com/
1xA5Lab https://example.net/
Z6lawAb https://example.org/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment