开发者

Batch file to edit multiple .txt files

开发者 https://www.devze.com 2023-01-01 04:09 出处:网络
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 th开发者_运维知识库e best way to achieve this?

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 th开发者_运维知识库e best way to achieve this?

Any advice would be appreciated.

Thanks

Stu


If this is Linux, then sed is the answer.


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.


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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消