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

后端 未结 30 2084
盖世英雄少女心
盖世英雄少女心 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:20

    To cut down on files to recursively sed through, you could grep for your string instance:

    grep -rl  /path/to/folder | xargs sed -i s^^^g
    

    If you run man grep you'll notice you can also define an --exlude-dir="*.git" flag if you want to omit searching through .git directories, avoiding git index issues as others have politely pointed out.

    Leading you to:

    grep -rl --exclude-dir="*.git"  /path/to/folder | xargs sed -i s^^^g
    

提交回复
热议问题