0

で使用する場合は、スペースを含むファイル名の引数と引数を使用findして正しく機能さxargsせることをお勧めします。-print0-0

今、私はpatterns次の内容で名前が付けられた次のファイルを持っています

a a a
b b b

textそして私は次の内容で名前が付けられたファイルを持っています

a
b b b

次のコマンドを実行すると、

cat patterns| xargs -ipattern grep pattern text

私は得る

b b b

これは、xargsが、、、、、、、の代わりに検索することを知っていa a ab b bことaを意味します。aabbb

私の質問は、上記の例に問題がないのはなぜですか?、、、、、を検索しaaの両方の行を返すと思いました。abbbtext

私は何が欠けていますか?

4

1 に答える 1

1

-iそして、-I(おそらく引用符で囲まれた)空白で区切られた文字列の使用から行に変更します。引用man xargs

   -I replace-str
          Replace occurrences of replace-str in the initial-arguments with  names  read  from
          standard  input.   Also,  unquoted blanks do not terminate input items; instead the
          separator is the newline character.  Implies -x and -L 1.

   --replace[=replace-str]
   -i[replace-str]
          This option is a synonym for -Ireplace-str if replace-str  is  specified,  and  for
          -I{} otherwise.  This option is deprecated; use -I instead.

デフォルト(つまりではない-I)モードでファイル名を操作するときは、スペース、タブ、および(このようなファイル名が良い考えではない)改行を保護する必要があります。したがって-0

于 2011-03-18T19:41:08.813 に答える