Citate:
If no -e, --expression, -f, or --file option is given, then the first non-option argument is taken as the sed script to interpret. All remaining arguments are names of input files; if no input files are specified, then the standard input is read.
s/regular expression/replacement/flags
The value of flags in the substitute function is zero or more of the following:
- N Make the substitution only for the N'th occurrence of the regular expression in the pattern space.
- g Make the substitution for all non-overlapping matches of the regular expression, not just the first one.
- p Write the pattern space to standard output if a replacement was made. If the replacement string is identical to that which it replaces, it is still considered to have been a replacement.
- w file Append the pattern space to file if a replacement was made. If the replacement string is identical to that which it replaces, it is still considered to have been a replacement.
所以find/-maxdepth 3 -type f -print0 | xargs -0 sed -e 's/[tT][eE][sS][tT][sS][tT][rR][iI][nN][gG]1/itworked!/g' -i
將工作,只要你想。
如果你不喜歡不區分大小寫的比賽難看的模式,你可以使用Perl,而不是sed的:(!)find/-maxdepth 3 -type f -print0 | xargs -0 perl -pe 's/teststring1/itworked!/ig' -i
殼牌解釋感嘆號,儘量不說? – ismail 2012-02-22 21:59:11
現在正在嘗試,將在幾分鐘內更新結果 – user1166981 2012-02-22 22:00:30
爲什麼要更改爲/ tmp,您的find命令使用'/'將搜索定位在根目錄。/tmp將被搜索,但是如果你打算搜索/ tmp及以下(你的-maxdepth 3),那麼可以使用'cd/tmp;找 。 -maxdepth ...'或者更簡單地說,'find/tmp -maxdepth ...',沒有最初的'cd/tmp;'。祝你好運。 – shellter 2012-02-22 22:03:06