[help]: Joining 20+ CSV files together

Discussion in 'Programming' started by dr_zloba, Dec 1, 2008.

  1. #1
    I need a little help as I am a complete novice at programming. i have 20+ CSV files and i need split them together into bigger one. Anyone have solution for this problem? please, help.
     
    dr_zloba, Dec 1, 2008 IP
  2. plvsoft

    plvsoft Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Why not use Excel or openoffice Calc?

    Patrice
     
    plvsoft, Dec 2, 2008 IP
  3. dr_zloba

    dr_zloba Well-Known Member

    Messages:
    156
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    145
    #3
    lol, thanks for advice, it is very valuable :D.
    now i have 200+ files and there are no any tools in Excel or OO to split them together into one file.
     
    dr_zloba, Dec 3, 2008 IP
  4. zdrol

    zdrol Peon

    Messages:
    19
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    This should work, assuming you just want to append one file one to the next.

    
    c:\>type a.txt
    a
    
    c:\>type b.txt
    b
    
    c:\>type a.txt b.txt > c.txt
    c:\>type c.txt
    a
    b
    
    Code (markup):
    or to make it easier, since you have so many csv files, place them all into one directory.

    
    c:\csv-files>for %G IN (*.csv) DO type %G >> c:\combined-output.csv
    
    Code (markup):
    Note you probably want to redirect the new file to a directory outside where you are working as we have here (c:\combined-output.csv) to avoid reading it in as part of *.csv.
     
    zdrol, Dec 3, 2008 IP
  5. pharmboy

    pharmboy Member

    Messages:
    30
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #5
    If they are csv files and they're on a unix filesystem, you can use the 'cat' command.

    cat file1 file2 file3 > bigfile

    If you're on windows, you can try using the 'type' command:

    type file1 file2 file3 >> bigfile
     
    pharmboy, Dec 3, 2008 IP
    dr_zloba likes this.
  6. dr_zloba

    dr_zloba Well-Known Member

    Messages:
    156
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    145
    #6

    Thanks, guys! These methods really work, exactly what I need. But now i have another question:
    this code works in win:
    c:\csv-files>for %G IN (*.csv) DO type %G >> c:\combined-output.csv
    Code (markup):
    Do any one have the same code solution but working on unix?
     
    dr_zloba, Dec 4, 2008 IP
  7. zdrol

    zdrol Peon

    Messages:
    19
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    for bash shell:

    
    
    for i in `ls *.csv`; do
    cat $i >> output
    done
    
    
    Code (markup):
    or simply

    
    cat *.csv >> out
    
    Code (markup):
     
    zdrol, Dec 4, 2008 IP
    dr_zloba likes this.
  8. dr_zloba

    dr_zloba Well-Known Member

    Messages:
    156
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    145
    #8
    Thanks again! +1 rep ;).
     
    dr_zloba, Dec 4, 2008 IP
  9. zdrol

    zdrol Peon

    Messages:
    19
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    No problem, glad I could be of help.
     
    zdrol, Dec 4, 2008 IP