在文件顶部附加文本 [英] append a text on the top of the file

查看:40
本文介绍了在文件顶部附加文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的 data.txt 文件顶部添加一个文本,此代码在文件末尾添加文本.如何修改此代码以将文本写入 data.txt 文件的顶部.提前感谢您的任何帮助.

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)

推荐答案

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

这篇关于在文件顶部附加文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆