LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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, 06: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 06:55 AM. Reason: Found the problem.
 
Old 04-17-2008, 09:14 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984
it wasn't realistically going to be anything else... removing from zero posts.
 
Old 04-19-2008, 07:44 AM   #3
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
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 04:06 AM
Split large file in several files using scripting (awk etc.) chipix Programming 14 10-29-2007 11:16 AM
Performance of ext3 file system with large files staham Red Hat 2 03-26-2007 07:06 AM
Combine multiple wmv files to one large file drkstr Linux - Software 4 04-26-2006 11:50 AM
Script file to replace large text blocks in files? stodge Linux - Software 0 09-27-2003 10:53 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:39 AM.

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
Open Source Consulting | Domain Registration