¶ 1 Leave a comment on paragraph 1 2 There may be times when you have a folder of text files that you wish to merge together into a single csv file. For instance, you might wish to use the Stanford Topic Modeling Tool on your data; this tool requires a csv file to import. Here is a simple script that will write each text file into a new line of a csv file. We found this script at the question and answer forum, Stack Overflow, and have modified it slightly.1 (nb, this only works on Windows. We’re looking for Mac, Linux options).
¶ 3 Leave a comment on paragraph 3 0 Save it with the file name text-to-csv.bat . The .bat extension is important, as it tells Windows that this is a batch file, meaning it is executable. Save the file in the folder where your text files are located. Before you double-click on it, to run it, open one of your text files and examine it. How many line breaks are in it? If it has three paragraphs, this script will only grab the first two paragraphs. In this line:
Leave a comment on paragraph 5 0
!line3!, just before the >> markers. When you run this script, it will create a csv file where the first column is the original text file’s name, the second column is the contents of line 1 (everything up to the first line break), the third column contains the contents of line 2 (everything up to the second line break), and so on.