Explain the three methods of batch replacement under linux: of perl sed shell

  • 2020-05-30 21:56:35
  • OfStack

In the construction of this website, found that a lot of new pages, suddenly found that each file needs to be modified 1 kind of content, 1 open 1 is very troublesome, so, summed up how to quickly modify 1 directory under a number of files for content replacement. The third method is used sparingly

Method 1 USES perl with the following command:


find -name ' The file name to look for ' | xargs perl -pi -e 's| The replaced string | The replaced string |g'

Method 2 USES the sed command as follows:


sed -i "s/ The original string / A new string /g" `grep The original string -rl directory `

Method 3 USES shell with the following command:


grep "abc" * -R | awk -F: '{print $1}' | sort | uniq | xargs sed -i 's/abc/abcde/g'


Related articles: