![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Reading the header of a tar file(posix header) | Tanvirk | Linux | 2 | 01-31-2008 05:50 AM |
| existing file to a fixed length file | cmanand | Shell Programming and Scripting | 3 | 01-25-2008 02:50 PM |
| adding existing disks to a 3510 array | malcqv | SUN Solaris | 2 | 12-21-2007 01:40 AM |
| SMF - Adding instances to existing manifest | craigp84 | SUN Solaris | 2 | 10-01-2007 03:55 AM |
| i want to delete a file based on existing file in a directory | srivsn | Shell Programming and Scripting | 3 | 04-11-2006 01:38 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Code:
sed -e '1i\HeaderGoesHere' originalFile > newFile |
|
#3
|
|||
|
|||
|
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
|
|||
|
|||
|
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 Code:
ex - myreallybigfile < addhdr |
|
#5
|
|||
|
|||
|
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 01:56 AM. |
|
#6
|
|||
|
|||
|
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 Code:
ed - myreallylargefile < addhdr_ed |
|||
| Google The UNIX and Linux Forums |