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

Chris Pinnock cjep at fawlty.net
Sat Sep 6 06:39:03 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.

You could do:

(echo "NEWLINE" && cat test.txt) > newfile



More information about the SunHELP mailing list