2012-02-22 14 views
0

本質的に、このコマンドがワンライナーとして端末に送信されたが意図したとおりに動作しない理由を理解したい。これは数分間実行されますが、 "teststring1"を含むテストファイルは置き換えられません。構文を根本的に変更することなく、または私がなぜこれをrootからやっているのかを尋ねるのではなく、誰もその理由を特定できないのでしょうか? man sedからFind/Sedが期待どおりに動作しない

cd /tmp;find/-maxdepth 3 -type f -print0 | xargs -0 sed -i 's/teststring1/itworked!/gI' 
+0

シェルは、感嘆符を解釈され、それなしでみては? – ismail

+0

ok今のところ試してみると、結果は数分で更新されます – user1166981

+1

なぜ/ tmpに変わるのか、あなたのfindコマンドは '/'を使ってあなたの検索をルートディレクトリに固定します。/tmpが検索されますが、/ tmp以下(あなたの-maxdepth 3)を検索するつもりなら、 'cd/tmp;見つける。 -maxdepth ... 'またはより簡単に' find/tmp -maxdepth ... '、初期の' cd/tmp; 'はありません。がんばろう。 – shellter

答えて

0

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は動作します。

あなたは大文字小文字を区別しないマッチのための醜いパターンが気に入らない場合は、代わりのsedのPerlを使用することができます(!)find/-maxdepth 3 -type f -print0 | xargs -0 perl -pe 's/teststring1/itworked!/ig' -i

関連する問題