Last active
June 5, 2018 20:02
-
-
Save biancalpadilla/fa4b67dfd1880524bef59a40587dcedf to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# You can convert any txt file into a csv file by changing the extension to .csv | |
# Look for a file called file.csv | |
FILE=$(ls -1 | grep file.csv) | |
NAME=${FILE%%.csv} | |
# Save the first line in the file as your header | |
head -1 $FILE > header.csv | |
# Save the rest of file (line 2 and on) as your data file | |
tail -n +2 $FILE > data.csv | |
# Save the header for the Column Split files | |
cut -d, -f -400 header.csv > header.1.csv | |
cut -d, -f 1,401-717 header.csv > header.2.csv | |
# Split data at every X number of lines | |
split -l 1000 data.csv | |
# Iterate over each split file | |
for a in x?? | |
do | |
# Add the header to each new split file | |
cat header.csv $a > $NAME.$a.csv | |
# Split by Columns (1-400) and add to new split file | |
cut -d, -f -400 $NAME.$a.csv > $NAME.$a.1.csv | |
# Split by Columns (1,400-717) and add to new split file | |
cut -d, -f 1,401-717 $NAME.$a.csv > $NAME.$a.2.csv | |
# Remove original split file | |
rm $NAME.$a.csv | |
done | |
# Remove the data file used to split | |
rm data.csv x?? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment