用于编辑多个 .txt 文件的批处理文件

发布于 2024-09-03 16:19:21 字数 113 浏览 3 评论 0原文

我有超过 1300 个 .txt 文件,我需要编辑第一行文本,将一个名称替换为另一个名称。有人可以建议实现这一目标的最佳方法吗?

任何建议将不胜感激。

谢谢斯图

I have over 1300 .txt files where I need to edit the first line of text, replacing one name for another. Can someone please advise of the best way to achieve this?

Any advice would be appreciated.

Thanks

Stu

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ゞ花落谁相伴 2024-09-10 16:19:21

如果这是 Linux,那么 sed 就是答案。

If this is Linux, then sed is the answer.

放我走吧 2024-09-10 16:19:21

使用 sed。这是一个简单的单行代码,可以完成您想要的操作:

sed -i '1s/oldtext/newtext/' *.txt

-i 告诉 sed 就地编辑文件。模式开头的 1 仅将其应用于第一行。 s// 结构替换了文本。

Use sed. Here's a simple one-liner that would do what you want:

sed -i '1s/oldtext/newtext/' *.txt

The -i tells sed to edit the files in-place. The 1 at the beginning of the pattern applies it only to the first line. The s// constrution replaces the text.

北渚 2024-09-10 16:19:21
perl -npi~ -e "s/old/new/g" file.txt

如果您使用的是 Windows 计算机,请安装 Strawberry Perl

perl -npi~ -e "s/old/new/g" file.txt

If you're on a Windows machine, install Strawberry Perl.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文