shellperl

Append a text to the top of a file


I want to add a text on the top of my data.txt file, this code add the text at the end of the file. how I can modify this code to write the text on the top of my data.txt file. thanks in advance for any assistance.

open (MYFILE, '>>data.txt');
print MYFILE "Title\n";
close (MYFILE)

Solution

  •  perl -pi -e 'print "Title\n" if $. == 1' data.text