简体   繁体   English

Linux找到并替换

[英]Linux find and replace

How can I replace "abc" with "abcd" on all files of a folder using shell? 如何使用shell将"abc"替换为文件夹的所有文件中的"abcd"

Is it possible using sed command? 是否可以使用sed命令?

Try the following command for the file file.txt: 对文件file.txt尝试以下命令:

sed -i 's/abc/abcd/g' file.txt


Try the following command for all files in the current folder: 对当前文件夹中的所有文件尝试以下命令:

find . -maxdepth 1 -type f -exec sed -i 's/abc/abcd/g' {} \;

For the files in the current directory and all subdirectories: 对于当前目录和所有子目录中的文件:

find . -type f -exec sed -i 's/abc/abcd/g' {} \;

Or if you are fan of xargs: 或者如果你是xargs的粉丝:

find . -type f  | xargs -I {}  sed -i 's/abc/abcd/g' {}
sed -i 's/abc/&d/g' *

应该管用。

是:

find /the/folder -type f -exec sed -i 's,\<abc\>,&d,g' {} \;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM