Append (cat) to beginning of file ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Append (cat) to beginning of file ?
# 1  
Old 12-09-2003
Question Append (cat) to beginning of file ?

Hi,

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.

Any ideas would be appreciated.

Thanks,
# 2  
Old 12-09-2003
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...
# 3  
Old 12-09-2003
control yes, but not enough...

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.

Chad.
# 4  
Old 12-09-2003
I assume that before doing the following you already have the header, trailer and detail files

in that case

cat header detail trailer > newfile

I hope I havent much misunderstood the question Smilie
# 5  
Old 12-09-2003
Quote:
cat header detail trailer > newfile
Won't that still copy the 5gb file ? I see how it is much more econimical as far as commands go though...


Thanks,
# 6  
Old 12-09-2003
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 Smilie
so what you need to really worry is that you do minimum possible operations on the huge file

but you cannot avoid the time for

1. open
2. read

on the file to have it changed Smilie
# 7  
Old 12-09-2003
penguin,

Thanks, that confirms my fear. However, I will try doing it in the one command and see how it works.

Thanks for your time and help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to append a string by cat and redirect to other file?

Hi, when I do cat for kernel parameters cat /proc/sys/kernel/sem >> /etc/sysctl.conf 4096 4096 32 128 The above command working with out any doubt but I want to pass it like below, need to append "kernel.sem =" and pass it to /etc/sysctl.conf kernel.sem = 4096... (2 Replies)
Discussion started by: stew
2 Replies

2. Shell Programming and Scripting

How to append in the beginning not at the end?

Hi, I now that >> will append text to the end of the text that is already inside the file. How to append the new text infront of the text that is already in the file. Thanks for any input. Regards, Chandu (3 Replies)
Discussion started by: chandrakanth
3 Replies

3. Shell Programming and Scripting

How to Append data to the content at the beginning of a variable?

Hi Guys, IF i have to append data to a variable, i simply use the following. What can i do to append data to the beginning? VAR+="data" (6 Replies)
Discussion started by: srkmish
6 Replies

4. Shell Programming and Scripting

Append Multiple files with file name in the beginning of line

Hi, I have multiple files having many lines like as bvelow: file Name a.txt abc def def xyz 123 5678 file Name b.txt abc def def xyz 123 5678 I would like to append files in the below format to a new file: file Name c.txt (7 Replies)
Discussion started by: rramkrishnas
7 Replies

5. Shell Programming and Scripting

Append file name to the beginning of each line

I want to append file names at the beginning of a line for each row file content abc.txt.gz 123|654|987 bcd.txt.gz 876|trf|kjh I want a single output file with below format abc.txt.gz|123|654|987 bcd.txt.gz|876|trf|kjh This one is working but only with unzip files,need to have... (3 Replies)
Discussion started by: rakesh5300
3 Replies

6. Shell Programming and Scripting

Append variable texts to the beginning of each line in all files in a directory

I am writing a code to append some numbers in the beginning of each line in all the files present in a directory. The number of files are really huge. The files are numbered as 1.sco, 2.sco, 4.sco (Note: 3.sco is missing). The files currently look like this: 1.sco 2 3 5 6 6 7My task is to... (4 Replies)
Discussion started by: shoaibjameel123
4 Replies

7. UNIX for Dummies Questions & Answers

Count Number Of lines in text files and append values to beginning of file

Hello, I have 50 text files in a directory called "AllFiles" I want to make a program that will go inside of the "AllFiles" Directory and count the number of lines in each individual text file. Then, the program will calculate how many more lines there are over 400 in each text file and... (7 Replies)
Discussion started by: motoxeryz125
7 Replies

8. UNIX for Dummies Questions & Answers

Append to beginning of a file

Hi, I have a file x which is being upated continuously. I want to add file y in the file x but at the beginning of file x. file x file y After commands file x eeee aaaa aaaa gggg bbbb bbbb hhhh... (2 Replies)
Discussion started by: baanprog
2 Replies

9. UNIX for Dummies Questions & Answers

Difference between cat , cat > , cat >> and touch !!!

Hi Can anybody tell the difference between Difference between cat , cat > , cat >> and touch command in UNIX? Thanks (6 Replies)
Discussion started by: skyineyes
6 Replies

10. UNIX for Dummies Questions & Answers

cat a file from end to beginning

Is there an option, for cat, head, tail, or is there any way, to display a file from last line to first? For example, my file looks like this: aaaa bbbb cccc eeee and I would like to print or display it like this: eeee cccc bbbb aaaa thanks (5 Replies)
Discussion started by: jpprial
5 Replies
Login or Register to Ask a Question