Operating System - HP-UX
1753809 Members
8182 Online
108805 Solutions
New Discussion юеВ

How to merge different files in one file?

 
N Gopal
Frequent Advisor

How to merge different files in one file?

Hi,

I am having 5 flat files say f1.out,f2.out,f3.out,f4.out,f5.out etc.

These files will be updated everyday. I want out put of all the files in one file say final.out. For that i am using below commands:

cat f1.out > final.out
cat f2.out >> final.out
cat f3.out >> final.out
cat f4.out >> final.out
cat f5.out >> final.out

I have to run these commands everyday.

But problem i am facing is that out put shows the content of f5.out only.

Can some one help me out that what is the correct way to do this?

Thanks
4 REPLIES 4
Anshumali
Esteemed Contributor

Re: How to merge different files in one file?

"I have to run these commands everyday."
You are running it manually or running through cron.

let me know if the issue is with manual execution also?

Anshu
Dreams are not which you see while sleeping, Dreams are which doesnt allow you to sleep while you are chasing for them!!
Hasan  Atasoy
Honored Contributor

Re: How to merge different files in one file?

Hi ;

cat f[1-5].out > final.out

Hasan
john korterman
Honored Contributor

Re: How to merge different files in one file?

Hi Gopal,

your commands look ok to me.
Alternatively, you could do it like this:

# cat f1.out f2.out f3.out f4.out f5.out > final.out

but it will bring the same result; if it looks as if you get only the result of f5.out, it must be because the other files are empty.


regards,
John K.
it would be nice if you always got a second chance
No Devices Found
New Member

Re: How to merge different files in one file?

Gopal,

To concat all the files to the single file you have to run the command like below I have given.

cat file1 file2 file3 >> Outputfile

Make sure your files are not empty. If anyone of them is empty then you wont get some results in your output file.