Skip to content

Instantly share code, notes, and snippets.

@getflourish
Last active February 13, 2020 09:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save getflourish/639ca998275a633cb889d313dd0d8c78 to your computer and use it in GitHub Desktop.
Save getflourish/639ca998275a633cb889d313dd0d8c78 to your computer and use it in GitHub Desktop.
CSV to Files
  1. Copy the script to the folder containing the CSV file
  2. Name the CSV input.csv or change the source file in the script
  3. Open Terminal and enter cd yourDirectory
  4. In Terminal, enter bash script.sh
  5. Files should be saved in the same folder
# Reads a CSV line by line
# Extracts columns
# Saves one file per row
# Filename is the content of the first column
# File format
extension="txt"
# Source
source="input.csv"
while read -r line
do
column1=$(echo $line | awk -F';' '{printf "%s", $1}' | tr -d '"')
column2=$(echo $line | awk -F';' '{printf "%s", $2}' | tr -d '"')
echo $column1 $column2
echo $column2 >"${column1}.${extension}"
done < $source
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment