LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Append all CSV files in a directory into one large file (https://www.linuxquestions.org/questions/programming-9/append-all-csv-files-in-a-directory-into-one-large-file-635973/)

br8kwall 04-17-2008 06:53 AM

Append all CSV files in a directory into one large file
 
I need to find all of the .csv files in a directory and append them (with these little breaks) into one large file. Why does this script only produce largefile.txt with the contents of the last file only? PS, I'm running on cygwin.

Code:

#!/bin/bash
# jcz 13-apr-08
##################################
echo " ******************************* "
echo " This script reads all csvs into a single file in this directory"
echo " ******************************* "

for filers in *.csv
do
echo "" >> largefile.txt
echo "" >> largefile.txt
echo "--------------------------------" >> largefile.txt
echo $filers >> largefile.txt
echo "--------------------------------" >> largefile.txt
cat $filers >> largefile.txt

done


Heh, found it as I was posting. The first append was a single so it was overwriting the file every loop.

The version above is fixed.

acid_kewpie 04-17-2008 09:14 AM

it wasn't realistically going to be anything else... :) removing from zero posts.

bigearsbilly 04-19-2008 07:44 AM

cat *.csv > largefile.txt


All times are GMT -5. The time now is 01:16 AM.