Sed+Grep Quickly replace lookup fields (replace strings in batches)

Format: sed -i "s/find field/replace field/g" `grep find field -rl path`

Command breakdown:

grep find field -rl path list all files of "find field" in "path"

sed -I "s/Find Field/Replace Field/g" In the above "Find Listed Files" (grep command), execute the "s/Find Field/Replace Field/g" operation, and apply the result of the operation to "Find Listed Files" on source files.

Note: The red characters are the keys on the TAB key of the keyboard

 

Example: Replace syslog in all files in the current directory with xlog
sed -i "s/xlog/syslog/g" `grep -rl xlog ./`

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324638978&siteId=291194637