How to use > in an xargs command?

后端 未结 3 1101
长情又很酷
长情又很酷 2020-12-02 03:47

I want to find a bash command that will let me grep every file in a directory and write the output of that grep to a separate file. My guess would have been to do something

3条回答
  •  爱一瞬间的悲伤
    2020-12-02 04:29

    A solution without xargs is the following:

    find . -mindepth 1 -maxdepth 1 -type f -exec sh -c "grep ABC '{}' > '{}.out'" \;
    

    ...and the same can be done with xargs, it turns out:

    ls -1 | xargs -I {} sh -c "grep ABC '{}' > '{}.out'"
    

    Edit: single quotes added after remark by lhunath.

提交回复
热议问题