Create a Backup
To create a backup file before overwriting the existing one, add the .bak parameter to the -i tag.
sed -i.bak 's/foo/FOO/g' example.txt
Match and Replace All Cases
To find and replace all instances of a word and ignore capitalization, use the I parameter:
sed -i 's/bar/linux/gI' example.txt
Reference Found String
Use the ampersand character (&) to reference the found string. For example, to add a forward slash (/) before every instance of foo in a file, use:
sed -i 's/foo/\/&/gI'example.txt
Recursive Find and Replace
Use the find command to search for files and combine it with sed to replace strings in files recursively. For example:
find -name 'example*' -exec sed -i 's/[a-z]/5/gI' {} +
来源:https://phoenixnap.com/kb/sed-replace
标签:foo,替换,命令,sed,example,txt,find,gI From: https://www.cnblogs.com/profesor/p/17757915.html