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 |
for i in /home/docs/text/*
do cat $i >> bigfile done or something along those lines. |
Or:
Code:
cat * >> bigfile |
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.
|
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... ;)
|
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 |
Edit: deleted irrelevant post
|
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 Quote:
Quote:
Quote:
|
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
|
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 |
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.
|
All times are GMT -5. The time now is 06:25 PM. |