[ale] help with a tiny shell script

Christopher Bergeron christopher at bergeron.com
Tue Nov 16 00:55:20 EST 2004


Jay, try this:

rm append.csv
echo > append.csv
for i in `cat *.csv`; do cat $i >> append.csv; echo -e "\n" >> 
append.csv; done

Basically what this will do is:
a) remove any existing append.csv file that you have (I'm assuming 
that's what you want)
b) create an empty file called append.csv (optional step; just added for 
robustness)
c) for each .csv file, cat it into append.cvs and then echo a newline 
after it

I've just started learning AWK and I have a feeling that it might be 
better suited for this, but you asked how to do it in bash.

I'd be interested to know how others would do this though - particularly 
because sed has some nasty quirks when it comes to newlines.

Best regards,
CB




jay wrote:

>Here's the scoop...I have about 330 csv files that are results files from a 
>survey.  I want to import them into a spreadsheet for graphing, but when 
>coding the survey in php, my partner and I didnt place a line break after 
>each results file finishes.  
>
>The result is 330 files like this: 
>
>2,0,0,1,1,3,1,10,2,0,2,1,1,0,	*	"short answer" 
>
>Each file is one line, with a set of comma deliminated numerical answers, then 
>one short answer question, separated by the star as you see above.  What I 
>want to do is basically: 
>
>cat *.csv > append.csv 
>
>but I want to add a linebreak between each file.  I can code this in python, 
>but that seems unnecessarily complicated, and I'm almost positive if I knew 
>how to utilize the shell better, I could do this in one command....can anyone 
>shed some light on this for me? 
>
>Thanks!
>
>-Jay
>_______________________________________________
>Ale mailing list
>Ale at ale.org
>http://www.ale.org/mailman/listinfo/ale
>
>  
>



More information about the Ale mailing list