Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Programming/Scripts

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 6th March 2009, 08:23
infinity2030 infinity2030 is offline
Junior Member
 
Join Date: Mar 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help with Shell Script Needed

Hi all,

I'm a newbie. I'm thinking of making a shell script which will list a directory for *.csv files and merge all the files into a single file called data.csv.

However, i have no idea how to. What i do currently is to manually issue the following command to merge multiple CSV files into one:-

cat file1.csv >> data.csv
cat file2.csv >> data.csv
etc..

I need a script to help me in doing so, so i need not worry about what file name would the csv be, and they'll all be merged into a single data.csv whenever i execute the script.

Can anyone help? Thanks alot!
Reply With Quote
Sponsored Links
  #2  
Old 7th March 2009, 15:47
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,749 Times in 2,579 Posts
Default

Try something like this:

Code:
for file in "$( /usr/bin/find /home/sqlbackup -name *.csv -type f )"
do
  cat $file >> data.csv
done
See
Code:
man find
for more details.
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #3  
Old 7th March 2009, 22:04
athmane athmane is offline
Junior Member
 
Join Date: Jan 2009
Location: Algeria
Posts: 11
Thanks: 2
Thanked 1 Time in 1 Post
 
Default

Try this (if the order is not important) and after cd-ing to your directory:
Code:
 
cat `find . -name "*.csv" 2> /dev/null` > data.csv
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
freebsd 7, samba 3, domain controller alexdimarco Suggest HOWTO 6 5th November 2010 17:54
Upgrade to php 5.2 in suse 10.1 gimhan90 Installation/Configuration 3 1st January 2009 21:32
Shell Script Execution Problem giganet Programming/Scripts 1 23rd December 2008 16:04
Please explain me this shell script. i.linus Programming/Scripts 1 13th September 2008 04:31
odbc Chad Installation/Configuration 0 10th April 2008 02:43


All times are GMT +2. The time now is 01:51.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.