Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I want a shell script to merge all files into a single file which are exist in a directory , But the merging should be done in the order of files created.
ex: there are 5 files in a folder i.e
a.txt -- > Created at 7.00 pm
b.txt -- > Created at 7.10 pm
c.txt -- > Created at 7.20 pm
d.txt -- > Created at 7.30 pm
e.txt -- > Created at 7.40 pm
Note:- The files are dynamically comes form the system and we do not know how many files will be there
Now all these files should be merge into a single file in the same order.
The first line creates (or overwrites if it already exists) new.txt with the single redirect.
The following lines with double redirect append to the file new.txt. If run in order they will append in order.
If they are fairly large you might want to put sleep statements in between.
If these files grow large you may wish to delete the originals after doing the append. You DO want to make sure the filesystem into which your putting your new.txt has enough space to handle this operation.
If a cron job is creating each of the txt files you could modify it so it does the append after creating the next file.
There are some excellent ideas offered. What you should do at this point is start writing your script.
Please note that LQ members are volunteers and we are here to help, however the customary way of this forum is to enable you to complete these tasks on your own so that you learn from them. Therefore no one here should be just writing a script for you, however we're happy to review what you have and offer suggestions as to what directions to take with it.
For starters, do you have a script language in mind? Such as bash, or other?
And do you have skills and knowledge to write a script?
I think this problem breaks down into two parts: (1) identifying and sorting the input files by time/date (2) concatenating them to a single file (which incidentally you don't end up adding that new file to your concatenation ...)
Please update us with some more information about your script language choice and any attempts you have put forth to trying to solve this problem.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.