How to do a recursive find/replace of a string with awk or sed?

后端 未结 30 2187
盖世英雄少女心
盖世英雄少女心 2020-11-22 06:39

How do I find and replace every occurrence of:

subdomainA.example.com

with

subdomainB.example.com

in eve

30条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 07:32

    grep -lr 'subdomainA.example.com' | while read file; do sed -i "s/subdomainA.example.com/subdomainB.example.com/g" "$file"; done

    I guess most people don't know that they can pipe something into a "while read file" and it avoids those nasty -print0 args, while presevering spaces in filenames.

    Further adding an echo before the sed allows you to see what files will change before actually doing it.

提交回复
热议问题