Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Merge *.csv files, each in separate sheets

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 11-30-2012
frhling frhling is offline
Registered User
 
Join Date: Nov 2012
Last Activity: 30 June 2014, 6:36 AM EDT
Posts: 17
Thanks: 3
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 Unix and Linux 11-30-2012
Yoda's Unix or Linux Image
Yoda Yoda is offline Forum Advisor  
Jedi Master
 
Join Date: Jan 2012
Last Activity: 2 September 2015, 1:18 PM EDT
Location: Galactic Empire
Posts: 3,423
Thanks: 240
Thanked 1,225 Times in 1,151 Posts
You can do this in Perl, search for examples using Spreadsheet::WriteExcel Perl module.
Sponsored Links
    #3  
Old Unix and Linux 11-30-2012
joeyg's Unix or Linux Image
joeyg joeyg is offline Forum Staff  
modérateur
 
Join Date: Dec 2007
Last Activity: 27 August 2015, 2:01 PM EDT
Location: Within two miles of a Dunkin donuts.
Posts: 2,364
Thanks: 86
Thanked 164 Times in 150 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 Unix and Linux 12-10-2012
frhling frhling is offline
Registered User
 
Join Date: Nov 2012
Last Activity: 30 June 2014, 6:36 AM EDT
Posts: 17
Thanks: 3
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 Unix and Linux 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 419 Times in 407 Posts
show some examples of CSV files and format, and tell us what you need get from them.
Sponsored Links
    #6  
Old Unix and Linux 12-11-2012
frhling frhling is offline
Registered User
 
Join Date: Nov 2012
Last Activity: 30 June 2014, 6:36 AM EDT
Posts: 17
Thanks: 3
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 Unix and Linux 12-11-2012
cero cero is offline
Registered User
 
Join Date: Aug 2006
Last Activity: 2 September 2015, 7:54 AM EDT
Posts: 416
Thanks: 4
Thanked 84 Times in 76 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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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:49 PM.