How to combine multiple csv files into a single excel sheet using unix shell scripting? How to combine multiple csv files into a single excel sheet using unix shell scripting? unix unix

How to combine multiple csv files into a single excel sheet using unix shell scripting?


Yes the are multiple ways to do what you want. Perl, Python and Ruby have the appropriate modules. Probably other scripting languages also. Depends on which scripting language you are comfortable with.

Here is a pointer to one way of doing what you want using Python: Python script to convert CSV files to Excel


The command to cat files together to produce a new file is cat. However, if you simply did a

 cat *csv >All.xls

you would also have header lines in the middle of the resulting files. There are two ways to work around this problem:

The first involves that you create temporary files out of each csv file, where the header line is missing, before putting together the pieces. This can be done using the tail command, for example

tail -n +2 2.csv >2_without_header.csv

The second possibility may or may not be applicable in your case. If - as it is often the case with CSV files - the order of the lines doesn't matter and duplicate lines can be ignored and - as it is likely in your case - the headers are identical, you could simply do a

sort -u *csv >All.xls


You can try awk '!a[$0]++' ./*.csv > ./all.xls This command will combine all the csv files in current folder and create a new file: all.xls with single header row.