Merge *.csv files, each in separate sheets | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Merge *.csv files, each in separate sheets

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 11-30-2012
frhling frhling is offline
Registered User
 
Join Date: Nov 2012
Last Activity: 3 January 2013, 9:46 AM EST
Posts: 13
Thanks: 2
Thanked 0 Times in 0 Posts
Merge *.csv files, each in separate sheets

Does anyone know how to Merge *.csv files, each in seperate sheets?
Sponsored Links
    #2  
Old 11-30-2012
Yoda's Avatar
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 24 April 2014, 6:15 PM EDT
Location: Galactic Empire
Posts: 3,285
Thanks: 227
Thanked 1,158 Times in 1,095 Posts
You can do this in Perl, search for examples using Spreadsheet::WriteExcel Perl module.
Sponsored Links
    #3  
Old 11-30-2012
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
 
Join Date: Dec 2007
Last Activity: 22 April 2014, 11:31 AM EDT
Location: Out running a Marathon.
Posts: 2,309
Thanks: 66
Thanked 150 Times in 140 Posts
Need more info

You can append them to one another.
You can paste them next to each other.
You could write something to do all the line 1's, then line 2's,...

What do you mean by merge?
    #4  
Old 12-10-2012
frhling frhling is offline
Registered User
 
Join Date: Nov 2012
Last Activity: 3 January 2013, 9:46 AM EST
Posts: 13
Thanks: 2
Thanked 0 Times in 0 Posts
There is a script which everyday generates a new csv file.
By merge I mean: each different sheets which were created for each day should be all together in 1 file but different sheets.
thats why just copy-paste everyday doesnt answer.
Sponsored Links
    #5  
Old 12-10-2012
rdcwayx rdcwayx is offline Forum Advisor  
Use nawk in Solaris
 
Join Date: Jun 2006
Last Activity: 22 March 2014, 12:27 PM EDT
Posts: 2,759
Thanks: 44
Thanked 418 Times in 406 Posts
show some examples of CSV files and format, and tell us what you need get from them.
Sponsored Links
    #6  
Old 12-11-2012
frhling frhling is offline
Registered User
 
Join Date: Nov 2012
Last Activity: 3 January 2013, 9:46 AM EST
Posts: 13
Thanks: 2
Thanked 0 Times in 0 Posts

Code:
#!/bin/bash
find /a/b  -name "*.log"  -mtime 0 -exec cat "{}" \; >> aa.log # finds all log files in a special path
grep -e XXX -e YYY aa.log | grep -v ZZZ | awk '{print $1 " " $2 ";" $3 ";" $9 ";" $11}' | cut -d ' ' -f3- <<<"$8" >> aa.csv # looks for XXX and YYY and ignores ZZZ, looks for fields: $1,.... and import then in aa.csv
sed -i '1iDate;Time;From;To' aa.csv # makes header as Date,Time,From,To echo "done."

as you see my headers are date, time, from, to. everyday it genereates new data based on this header with a new date.
I just want each date(each new generated sheet) be in one csv next to the yesterday generated sheet.

preferably not to use perl.

Moderator's Comments:
Please use code tags for code and data

Last edited by Scrutinizer; 12-11-2012 at 05:36 AM.. Reason: code tags
Sponsored Links
    #7  
Old 12-11-2012
cero cero is offline
Registered User
 
Join Date: Aug 2006
Last Activity: 24 April 2014, 8:40 AM EDT
Posts: 352
Thanks: 3
Thanked 61 Times in 56 Posts
With sheet you mean a worksheet in MS-Excel? csv (Comma-Seperated-Values or Character-Separated-Values) is a file format that does not support a construct called sheet. Excel is an application you can use to view and edit .csv files, but you can use any editor/viewer/pager to do so.
If you need multiple csv-files on different Excel-worksheets you'll have to use an Excel-file (.xls or .xlsx) to store them.
Why not perl? It has good libraries for this task and to my knowledge is the most used tool to handle Excel-files in scripts.

Last edited by cero; 12-11-2012 at 06:29 AM.. Reason: Typos
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
create separate files from one excel file with multiple sheets harris Shell Programming and Scripting 3 10-05-2012 02:38 AM
Merge 2 CSV files using sed NewToSed Shell Programming and Scripting 9 04-24-2011 12:19 PM
Merge 2 csv files with awk loloAix Shell Programming and Scripting 6 12-16-2010 04:32 AM
How to create a CSV File by reading fields from separate files mayanksargoch Shell Programming and Scripting 2 07-07-2010 04:11 AM
Add multiple .csv files as sheets to an excel file in unix. libin4u2000 Shell Programming and Scripting 2 01-20-2009 10:20 PM



All times are GMT -4. The time now is 07:39 PM.