Linux Command|How to replace the same string in multiple files with another string at once


Describes the command to replace the same string in multiple files with another string at once.


Command to replace the same string in multiple files at once

When you specify the "String before replacement" and "String after replacement" in the command below and execute the command, the character strings in multiple files whose file names end with ".txt" will be displayed. You can replace the "character string before replacement" with the "character string after replacement" all at once.


・Command

find /work/*.txt | xargs -L 1 sed -i 's/String before replacement/String after replacement/g'


For example, if you want to replace the string "apple" with "orange" in multiple files test_01.txt, test_02.txt, and test_03.txt under the /work directory, execute the command below to replace them all at once. I can do it.


・Command

find /work/*.txt | xargs -L 1 sed -i 's/apple/orange/g'


This is useful even when performing substitution operations in bash shell scripts.




スポンサーリンク

0 件のコメント :

コメントを投稿