- Copy the script to the folder containing the CSV file
- Name the CSV
input.csv
or change thesource
file in the script - Open Terminal and enter
cd yourDirectory
- In Terminal, enter
bash script.sh
- Files should be saved in the same folder
Last active
February 13, 2020 09:36
-
-
Save getflourish/639ca998275a633cb889d313dd0d8c78 to your computer and use it in GitHub Desktop.
CSV to Files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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