2020.3.28
In Windows 10, how to combine many csv (or txt) files into one file
I had to combine many csv files (more than 300) into one csv file. The details of the problem are as follow. A math professor in my office kindly told me how to do.
My problem (difficulty)
1) I have many data files about the houses in a country. The information is in House.csv files in village subfolders. The folder structure is as follow. Each village subfolder contains one House.csv files.
2) The point of my problem was that there are many Village subfolders (as stated above, > 300). If I do copy-and-paste by hand, I will inevitably make some mistakes.
How to do it in Windows 10
Use "cat" command in PowerShell or Command Prompt.
a) We need to change the settings of our Windows 10 to use "cat" command, which is originally in the Linux system.[1] To activate Linux commands in Windows 10, please refer to, for example,
https://www.geeksforgeeks.org/how-to-run-linux-commands-on-windows-10/
(accessed on March 28, 2020)
A website in Japanese is, for example,
https://se-abeaver.com/wsl2-guide/
(accessed on October 27, 2023)
b) Activate PowerShell or Command Prompt.
c) In our example, go to (change directories) "Country" folder.
d) In "Country" folder, activate "bash" (type "bash" and hit enter key).
e) Type the following command
cat ./*/*/House.csv > combinedHouse.csv
f) You can find ( I go hope) combinedHouse.csv file in the current directry: Country.
Above, ./*/* is the wildcard that indicates sub subfolders (cdeVillage, difVillage, ...) under the current folder country