Help with Shell Script Needed

Discussion in 'Programming/Scripts' started by infinity2030, Mar 6, 2009.

  1. infinity2030

    infinity2030 New Member

    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!
     
  2. falko

    falko Super Moderator ISPConfig Developer

    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.
     
  3. athmane

    athmane New Member

    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
    
     

Share This Page