LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 04-17-2008, 07:53 AM   #1
br8kwall
LQ Newbie
 
Registered: Aug 2005
Location: Youngstown, NY
Distribution: Debian
Posts: 15

Rep: Reputation: 0
Append all CSV files in a directory into one large file


I need to find all of the .csv files in a directory and append them (with these little breaks) into one large file. Why does this script only produce largefile.txt with the contents of the last file only? PS, I'm running on cygwin.

Code:
#!/bin/bash
# jcz 13-apr-08
##################################
echo " ******************************* "
echo " This script reads all csvs into a single file in this directory"
echo " ******************************* "

for filers in *.csv
do
echo "" >> largefile.txt
echo "" >> largefile.txt
echo "--------------------------------" >> largefile.txt
echo $filers >> largefile.txt
echo "--------------------------------" >> largefile.txt
cat $filers >> largefile.txt

done

Heh, found it as I was posting. The first append was a single so it was overwriting the file every loop.

The version above is fixed.

Last edited by br8kwall; 04-17-2008 at 07:55 AM. Reason: Found the problem.
 
Old 04-17-2008, 10:14 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,415

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
it wasn't realistically going to be anything else... removing from zero posts.
 
Old 04-19-2008, 08:44 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,314

Rep: Reputation: 175Reputation: 175
cat *.csv > largefile.txt
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
efficiently break large file into small files: Perl? coldy78 Programming 10 12-11-2007 05:06 AM
Split large file in several files using scripting (awk etc.) chipix Programming 14 10-29-2007 12:16 PM
Performance of ext3 file system with large files staham Red Hat 2 03-26-2007 08:06 AM
Combine multiple wmv files to one large file drkstr Linux - Software 4 04-26-2006 12:50 PM
Script file to replace large text blocks in files? stodge Linux - Software 0 09-27-2003 11:53 AM


All times are GMT -5. The time now is 08:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration