Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
google site



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-09-2003
CBZ CBZ is offline
Registered User
 

Join Date: Dec 2003
Location: CT
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
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,
Sponsored Links
  #2  
Old 12-09-2003
oombera's Avatar
oombera oombera is offline Forum Advisor  
Registered User
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
Thanks: 0
Thanked 1 Time in 1 Post
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
CBZ CBZ is offline
Registered User
 

Join Date: Dec 2003
Location: CT
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
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
linuxpenguin's Avatar
Registered User
 

Join Date: May 2002
Location: India
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
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
  #5  
Old 12-09-2003
CBZ CBZ is offline
Registered User
 

Join Date: Dec 2003
Location: CT
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
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
linuxpenguin's Avatar
Registered User
 

Join Date: May 2002
Location: India
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
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

but you cannot avoid the time for

1. open
2. read

on the file to have it changed
  #7  
Old 12-09-2003
CBZ CBZ is offline
Registered User
 

Join Date: Dec 2003
Location: CT
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
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.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Add text to beginning of file donkey Shell Programming and Scripting 2 08-24-2007 07:24 AM
input a line at the beginning of every file in a directory? Terrible Shell Programming and Scripting 6 08-16-2006 06:42 AM
Adding a character in the beginning of every line in a .dat file Cool Coder Shell Programming and Scripting 2 12-22-2005 05:47 AM
Append a field to the end of each line of a file based on searching another file. ultimate Shell Programming and Scripting 2 03-29-2005 10:21 AM
cat a file from end to beginning jpprial UNIX for Dummies Questions & Answers 5 03-31-2001 08:14 AM



All times are GMT -4. The time now is 07:35 AM.