[SunHELP] insert one line at beginning of text file; efficiently

Phil Stracchino alaric at caerllewys.net
Tue Sep 2 17:11:23 CDT 2003


On Tue, Sep 02, 2003 at 05:51:34PM -0400, Markham, Richard wrote:
> I need to insert a line at the beginning of text files and would like to
> know if the following would be the most efficient way of doing so.
> 
> $ cat test.txt
> This is the original test data. 
> $ echo "new line" > tmp.new
> $ cat test.txt >> tmp.new
> $ mv tmp.new test.txt
> $ cat test.txt
> new line
> This is the original test data.
> 
> This code will be intercepting print data which could be lengthy and 
> that is why I am concerned with efficiency.  If I have to go with temp
> files I will add a time stamp to avoid multiple tasks overwritting 
> each other.

Is this a one-time job, or an ongoing thing?  Where does the original
test.txt come from?

This is probably a very inefficient way to do it, yes.  But it's hard to
be able to pick a more efficient one without knowing more about what
you're doing.



-- 
 .*********  Fight Back!  It may not be just YOUR life at risk.  *********.
 : phil stracchino : unix ronin : renaissance man : mystic zen biker geek :
 :  alaric at caerllewys.net : alaric-ruthven at earthlink.net : phil at latt.net  :
 :   2000 CBR929RR, 1991 VFR750F3 (foully murdered), 1986 VF500F (sold)   :
 :    Linux Now!   ...Because friends don't let friends use Microsoft.    :



More information about the SunHELP mailing list