怎么把find的结果用引号包含起来,然后给其他的命令去处理?
find . -name "*.m" | xargs -n 10 grep -inrE "#define.*http" > x.txt
思路是这样的:
首先查找到所有.后缀的文件,
然后每次取出10条文件,从文件中查找正则表达式.
最后,将结果重定向到文件中..
但是,这样有一个问题就是,当路径中包含了一个空格的时候,就找不到路径了.
所以,想将find的结果集合中的每一条路径使用引号包起来.
我该怎么做?
1
hcymk2 2015-01-05 17:54:42 +08:00 1
-0 Input items are terminated by a null character instead of by whitespace, and the quotes and backslash are not special (every character is taken literally). Dis-
ables the end of file string, which is treated like any other argument. Useful when input items might contain white space, quote marks, or backslashes. The GNU find -print0 option produces input suitable for this mode. |
2
urmyfaith OP @hcymk2
谢谢.解决我的问题了.在man手册也看到了. ``` −0 Change xargs to expect NUL (‘‘\0’’) characters as separators, instead of spaces and newlines. This is expected to be used in concert with the −print0 function in find(1). ``` 原来在设计exargs的时候就考虑到这个问题了. 最后的命令是: ``` find . -name "*.m" -print0 | xargs -n 10 -0 grep -inrE "#define.*http" > x.txt ``` thanks again. |