How do I include a pipe | in my linux find -exec command?

后端 未结 6 663
情深已故
情深已故 2020-11-28 17:51

This isn\'t working. Can this be done in find? Or do I need to xargs?

find -name \'file_*\' -follow -type f -exec zcat {} \\| agrep -dEOE \'grep\' \\;
         


        
6条回答
  •  失恋的感觉
    2020-11-28 18:15

    If you are looking for a simple alternative, this can be done using a loop:

    for i in $(find -name 'file_*' -follow -type f); do
      zcat $i | agrep -dEOE 'grep'
    done
    

    or, more general and easy to understand form:

    for i in $(YOUR_FIND_COMMAND); do
      YOUR_EXEC_COMMAND_AND_PIPES
    done
    

    and replace any {} by $i in YOUR_EXEC_COMMAND_AND_PIPES

提交回复
热议问题