0

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

Stuart
  • 1
  • 1
  • For a windows solution, see this question: http://stackoverflow.com/questions/60034/how-can-you-find-and-replace-text-in-a-file-using-the-windows-command-line-envir – James Bradbury Feb 25 '16 at 09:22

3 Answers3

0

If this is Linux, then sed is the answer.

eemz
  • 1,183
  • 6
  • 10
0

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.

Edward Dale
  • 29,597
  • 13
  • 90
  • 129
0
perl -npi~ -e "s/old/new/g" file.txt

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

Robert Wohlfarth
  • 1,761
  • 11
  • 10