Created
October 22, 2018 15:09
-
-
Save mhkeller/0953799f5673cb205fbb6ff95581d306 to your computer and use it in GitHub Desktop.
Concatenate csv files
This file contains 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
# Adapted from https://unix.stackexchange.com/questions/60577/concatenate-multiple-files-with-same-header#170692 | |
# `head -1` gets first line of the file of the file and stashes them as the header row into `all.txt` | |
# `tail -n +2 -q *.csv >> all.txt` grabs every csv file from the second row down and stashes them into `all.txt` | |
# `all.txt` is a csv file but we use the txt extension to avoid it being captured in the `*.csv` glob. | |
# You could also output to a csv file by having your input files share a naming convention such as `file-001.csv` and glob on `file*.csv` | |
# But renaming `all.txt` to `all.csv` is sometimes easier than worrying about a naming convention and txt and csvs are the same thing | |
head -1 my-csv-01.csv > all.txt; tail -n +2 -q *.csv >> all.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment