The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Reading the header of a tar file(posix header) Tanvirk Linux 2 01-31-2008 08:50 AM
existing file to a fixed length file cmanand Shell Programming and Scripting 3 01-25-2008 05:50 PM
adding existing disks to a 3510 array malcqv SUN Solaris 2 12-21-2007 04:40 AM
SMF - Adding instances to existing manifest craigp84 SUN Solaris 2 10-01-2007 06:55 AM
i want to delete a file based on existing file in a directory srivsn Shell Programming and Scripting 3 04-11-2006 04:38 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-23-2008
shash shash is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 21
Adding header to an existing file

Dear All,

I need to add a header of one line to an already existing file.
I know that it can be achieved by the following:

echo "Header" > newfile
cat file1 >> newfile

But my problem is that file is huge and there is no space for creating a new file every time. Is there a way that I can add header without creating a new file?

Thanks
Shash
  #2 (permalink)  
Old 07-23-2008
sysgate's Avatar
sysgate sysgate is offline Forum Advisor  
Unix based
  
 

Join Date: Nov 2006
Location: Bulgaria
Posts: 1,318
Code:
sed -e '1i\HeaderGoesHere' originalFile > newFile
  #3 (permalink)  
Old 07-23-2008
shash shash is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 21
Thanks for the reply sysgate. But, I don't want to create a new file.
Is there a way I can add the header in the existing file itself.

Thanks
Shash
  #4 (permalink)  
Old 07-23-2008
Vi-Curious Vi-Curious is offline
Registered User
  
 

Join Date: Jul 2008
Location: Texas
Posts: 129
If this is something you will need to do repeatedly, I suppose you could try something with an ex script. If you had something like this in a file named addhdr:
Code:
 
1i
this is what my header will be
.
x
And you would run it like this:
Code:
 
ex - myreallybigfile < addhdr
  #5 (permalink)  
Old 07-24-2008
shash shash is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 21
Thanks Vi-Curious!. It works for a small file. But I'm encountering an error stating Tmp file too large
while carrying out for a much bigger file.

Thanks
Shash

Last edited by shash; 07-24-2008 at 04:56 AM..
  #6 (permalink)  
Old 07-24-2008
Vi-Curious Vi-Curious is offline
Registered User
  
 

Join Date: Jul 2008
Location: Texas
Posts: 129
Ok, so your file is too large. We need to use a "large file" safe editor. Switch from ex to ed and modify the end of the command file.

File addhdr_ed
Code:
 
1i
this is the 1st line of the header
this is the 2nd line of the header (if needed)
.
w
q
Execute as before, but using ed:
Code:
 
ed - myreallylargefile < addhdr_ed
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On




All times are GMT -4. The time now is 04:41 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0