Title: FW: How do you pipe text to the top of a file?

This script does it in perl.
Run it as       "perl foo <filename> <text to append>"
--------------------------------------------------------------
open (FH, "+< $ARGV[0]");
shift @ARGV; foreach (@ARGV) { $line .= "$_ "}
$line .= "\n"; $line .= $_ while (<FH>);
seek(FH, 0, 0); print FH $line; close(FH);
---------------------------------------------------------------


On Wed, Apr 10, 2002 at 12:04:33PM -0400, Werner Puschitz wrote:
>>
>>  echo test | cat - test.txt > new.txt
                                        && mv new.txt test.txt

Emmanuel

original message was:

>echo test >> test.txt

>appends the word "test" at the bottom of a file called "test.txt"

>How do you pipe text to the top of a file?

>You could use the custom print command to
>pipe the file into a temp file and then cat the file you want to append to
>into that temp file, then overwrite the existing file. Ummm... there must be
>a better way...Perl, anyone?

>ross





_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to