LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Closed Thread
  Search this Thread
Old 05-19-2006, 12:15 AM   #1
baddah
Member
 
Registered: Feb 2006
Location: Cape Town,South Africa
Distribution: Fedora Core 8
Posts: 188

Rep: Reputation: 30
combine multiple files into one file?


Hi is there a easy way to combine all files,say in a directory, into one big file that contains all the information of the files together?i know something like

>>cat file1 file2 file3 .... >> bigfile

might work,but what if the directory has 1000 files in int?i dont want to type every file's name..It's just normal files containing text i want to combine.Thanks
 
Old 05-19-2006, 12:23 AM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
for i in /home/docs/text/*
do
cat $i >> bigfile
done

or something along those lines.
 
Old 05-19-2006, 12:28 AM   #3
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
Or:
Code:
cat * >> bigfile
 
Old 05-19-2006, 12:38 AM   #4
baddah
Member
 
Registered: Feb 2006
Location: Cape Town,South Africa
Distribution: Fedora Core 8
Posts: 188

Original Poster
Rep: Reputation: 30
brilliant,thanks.feel a bit stupid that i could not figure that one out by myself,its early in the morning that's my excuse.
 
Old 05-19-2006, 12:43 AM   #5
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
It's not immediately obvious that it'll work until you see that the '*' is expanded by bash to an alphabetical list of the files in the directory. At least that was my feeling when someone pointed it out to me...
 
Old 07-12-2006, 04:42 AM   #6
baddah
Member
 
Registered: Feb 2006
Location: Cape Town,South Africa
Distribution: Fedora Core 8
Posts: 188

Original Poster
Rep: Reputation: 30
Hi,another question on this i have.Please reply if you know the answer.what if i want to store the filename of the small file in the bigfile as well?how can i do this.

For instance say in directory /test there are 2 files test1 and test2.I want to combine them into one big file,but append after each line the filename that the original data was in.Is there an easy enough way to do this??

Thanks
 
Old 07-12-2006, 06:40 AM   #7
OdieQ
Member
 
Registered: Jan 2004
Location: Stockholm, Sweden
Distribution: Debian, Slackware
Posts: 71

Rep: Reputation: 15
Edit: deleted irrelevant post

Last edited by OdieQ; 07-12-2006 at 07:43 AM.
 
Old 07-12-2006, 06:49 AM   #8
OdieQ
Member
 
Registered: Jan 2004
Location: Stockholm, Sweden
Distribution: Debian, Slackware
Posts: 71

Rep: Reputation: 15
Sorry, I misread your question. I assume now that you want something like in my example below.

That can be achieved by writing:
Code:
(for r in *;do sed s/\$/\ $r/ < "$r";done) > bigfile
file1
Quote:
Albert
August
Arnold
file2
Quote:
Bertha
Brad
Bart
bigfile
Quote:
Albert file1
August file1
Arnold file1
Bertha file2
Brad file2
Bart file2
 
Old 07-12-2006, 07:34 AM   #9
baddah
Member
 
Registered: Feb 2006
Location: Cape Town,South Africa
Distribution: Fedora Core 8
Posts: 188

Original Poster
Rep: Reputation: 30
Perfect!!(the second one..)Thank you very much.I must really force myself to get into bash scripting,but the syntax is so confusing.but anyway,thanks
 
Old 09-06-2011, 10:59 AM   #10
shyamsandeep
LQ Newbie
 
Registered: Sep 2011
Posts: 3

Rep: Reputation: Disabled
could some one please help me with code on how to merge two files as belowm, the delimiter could be any thing such as tab, space , coma anything, below is a tab

file1
Quote:
Albert
August
Arnold

file2
Quote:
Bertha
Brad
Bart

bigfile
Quote:
Albert Bertha
August Brad
Arnold Bart

Thanks
Sandeep
 
Old 09-06-2011, 11:22 AM   #11
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Please don't resurrect old threads with a new question. Furthermore you've posted a new thread here: please see the answers and follow discussion there.
 
  


Closed Thread


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
Combine multiple wmv files to one large file drkstr Linux - Software 4 04-26-2006 11:50 AM
Multiple Boxes to Combine CPU-Power wwnexc Linux - Networking 6 01-24-2006 10:36 AM
Combine multiple WAN connections quentusrex Linux - Networking 3 01-07-2006 01:45 AM
Command to combine several files as a single file, etc. satimis *BSD 3 06-10-2004 03:59 AM
Best way to combine files? JockVSJock Programming 4 04-25-2004 07:38 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:55 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
Open Source Consulting | Domain Registration