Batch file to edit multiple .txt files
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.
精彩评论