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 Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to remove FIRST Line of huge text file on Solaris madoatz UNIX for Dummies Questions & Answers 5 06-23-2007 01:19 PM
Insert text file at a certain line. insania Shell Programming and Scripting 4 08-01-2006 02:46 AM
insert word in each line of a file atticus Shell Programming and Scripting 7 03-23-2006 02:15 AM
Failed to insert string into file before line nir_s Shell Programming and Scripting 7 07-26-2005 01:37 AM
insert a line in a file RishiPahuja Shell Programming and Scripting 7 06-22-2005 03:47 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 03-07-2005
shriek shriek is offline
Registered User
  
 

Join Date: Feb 2005
Posts: 4
Insert a line as the first line into a very huge file

Hello,

I need to insert a line (like a header) as the first line of a very huge file (about 3 ml rows). I am able to do it with sed, but redirecting the output and creating a new file takes quite some time. I was wondering if there was a more efficient way of doing it?

Any help would be greatly appreaciated.

Rds
Shriek
  #2 (permalink)  
Old 03-07-2005
bhargav's Avatar
bhargav bhargav is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2004
Location: USA
Posts: 511
Let 's say header is redirected to a file 'tmp'
If larger file is 'file1'


what about

Code:
cat tmp file1 > file2
mv file2 file1
It may be faster than 'sed'
  #3 (permalink)  
Old 03-08-2005
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,206
Or rather than using sed you could use ed, you dont redirect the output then, but I don't know if it would be any quicker.
  #4 (permalink)  
Old 03-09-2005
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,407
perl -pi -e 'print "header\n" if $.==1' file1
Sponsored Links
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 02:11 AM.


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