bat函数来编辑文件(在文件开头添加行) [英] bat function to edit a file (add line to start of a file)

查看:314
本文介绍了bat函数来编辑文件(在文件开头添加行)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的bat脚本中,如何使用打开文件open.txt并将以下行添加到顶部

In my bat script, what do I use to open a file called open.txt and add the following line to the top

SOME TEXT TO BE ADDED

可以在.bat脚本中处理类似这样的小修改

Can small edits like this be handled in a .bat script

推荐答案

当然可以,例如:

copy original.txt temp.txt
echo.SOME TEXT TO BE ADDED>original.txt
type temp.txt >>original.txt
del temp.txt

第一行是文件的临时副本.第二行用要添加的行覆盖文件(尤其要注意,要添加的文本和>重定向操作符之间缺少空格-echo习惯于包含这样的空格).

The first line makes a temporary copy of the file. The second line overwrites the file with the line you want to add (note particularly the lack of spaces between the text being added and the > redirection operator - echo has a nasty habit of including such spaces).

第三行使用附加重定向运算符>>将原始文件添加到新文件的末尾,然后最后一行删除临时文件.

The third line uses the append redirection operator >> to add the original file to the end of the new one, then the final line deletes the temporary file.

这篇关于bat函数来编辑文件(在文件开头添加行)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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