Fairly new to unix scripting, hoping to get some help.
using AIX v5
Basically I have 3 files 1). Header record 2). many detail record 3). Trailer record
My desired result is 1 file which contains Heaeder, Detail, Trailer
Currenty I am using a series of:
cat detail >> header
rm detail
cat trailer >> header
rm trailer
mv header detail
Now the problem with this approach is that my detail file quite often is in excess of 5gb, so the time is takes to do the cat seems like a waste of time to me. I would really like to be able to concatenate the header to the beginning of the detail and only "move" the one record.
I assume some program is creating the "detail" file .. how much control over that program do you have? If you could go into it and tell it to stick your header information at the top of the file before it runs through the loop or whatever piece of code creates the 5gb detail file, that might be best...
We do have control over the program creating the files, but the header and trailer are created based upon the sum of the detail records so not possible to hold off writing all the details.
To edit any file in any way you will have to read it directly or indirectly
so any command/script/method will take atleast the time required to open the file and save it bak
so what you need to really worry is that you do minimum possible operations on the huge file
You could have a dummy header that reserves enough space for the real header. For example, it might say:
line count = xxxxxxx
Then you append your detail records and compute the real header. Finally you rewrite the first n bytes where n is the number of bytes in the header. To rewrite the first bytecount bytes use:
Hi, as Perderabo suggested, you may leave space at the beginning and end with strings like space_for_header and space_for_footer. You may at last use stream editor sed to replace those strings with your header and footer info. I am not sure about the time taken but you can sure use your time wisely if you use the sed command in a script and let it run in the background. Hope it helps. Cheers