[ale] help with a tiny shell script - correction

Christopher Bergeron christopher at bergeron.com
Tue Nov 16 01:00:03 EST 2004


Correction:  the for line should read:
for i in `\ls *.csv`; do cat $i >> append.csv; echo -e "\n" >> 
append.csv; done
(for i in backtick backslash ls start dot csv backtick semicolon ...)

Also, it should be noted that this will concatenate the output of EVERY 
.csv file in that directory.  If you have .csv files you don't want 
appended to "append.csv" you need to make adjustments accordingly.

Kind regards,
CB


Christopher Bergeron wrote:

> 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