Hi,
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
Hi,
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
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.