Chinaunix

标题: find . -name "*.htm"|xargs -i grep -l "ffmail" {}|more [打印本页]

作者: zhengwei_zw    时间: 2007-03-16 14:33
标题: find . -name "*.htm"|xargs -i grep -l "ffmail" {}|more
怎么在bsd下这个xargs -i就莫发用了?
我想查找某部分文件内容中是否喊有某个字符,并且打印出这些文件名
现在bsd下就不行,linux下可以。
作者: Edengundam    时间: 2007-03-16 14:39
J replstr
             If this option is specified, xargs will use the data read from
             standard input to replace the first occurrence of replstr instead
             of appending that data after all other arguments.        This option
             will not affect how many arguments will be read from input (-n),
             or the size of the command(s) xargs will generate (-s).  The
             option just moves where those arguments will be placed in the
             command(s) that are executed.  The replstr must show up as a dis-
             tinct argument to xargs.  It will not be recognized if, for
             instance, it is in the middle of a quoted string.        Furthermore,
             only the first occurrence of the replstr will be replaced.  For
             example, the following command will copy the list of files and
             directories which start with an uppercase letter in the current
             directory to destdir:

                   /bin/ls -1d [A-Z]* | xargs -J % cp -rp % destdir
作者: zhengwei_zw    时间: 2007-03-16 14:45
ns# find . -name "*.htm" | xargs -J grep -l "http://%7" {} ;
xargs: illegal option -- l
usage: xargs [-0opt] [-E eofstr] [-I replstr [-R replacements]] [-J replstr]
             [-L number] [-n number [-x]] [-P maxprocs] [-s size]
             [utility [argument ...]]
ns#
不得行。。。
作者: zhengwei_zw    时间: 2007-03-16 14:46
我想查找某部分文件内容中是否喊有某个字符或者某字符串,并且打印出这些文件名
这个是我要实现的功能,在linux下可以用find . -name "*.htm"|xargs -i grep -l "ffmail" {}|more这样实现
但bsd下就不行,请高手指点……
作者: zhengwei_zw    时间: 2007-03-16 14:48
http://www.freebsd.org/cgi/man.c ... ASE&format=html
这里man我看不明白。
ns# find . -name "*.htm" | xargs -J grep -l "http://%7" {}
xargs: illegal option -- l
usage: xargs [-0opt] [-E eofstr] [-I replstr [-R replacements]] [-J replstr]
             [-L number] [-n number [-x]] [-P maxprocs] [-s size]
             [utility [argument ...]]
ns#
作者: Edengundam    时间: 2007-03-16 14:51
xargs -I % grep -l http://%7 %


J 替换一次...I 可以 配合-x替换多次

[ 本帖最后由 Edengundam 于 2007-3-16 14:55 编辑 ]
作者: 一梦如是    时间: 2007-03-16 14:51
xargs -I{} grep -l "ffmail" {}

不过-I这个参数可能有BUG,到您系统下的man xargs确认一下是否还需要其他参数增大最大输入行。
作者: zhengwei_zw    时间: 2007-03-16 14:54
grep: insert_image.php: No such file or directory
xargs -J % grep -l http://%7 % 用这个
提示grep: insert_image.php: No such file or directory
作者: zhengwei_zw    时间: 2007-03-16 14:56
ns# find /home/user -name "*.php"|xargs -I{} grep -l "http://%7" {}
xargs: illegal option -- l
usage: xargs [-0opt] [-E eofstr] [-I replstr [-R replacements]] [-J replstr]
             [-L number] [-n number [-x]] [-P maxprocs] [-s size]
             [utility [argument ...]]
ns#
作者: zhengwei_zw    时间: 2007-03-16 14:58
原帖由 Edengundam 于 2007-3-16 14:51 发表
xargs -I % grep -l http://%7 %


J 替换一次...I 可以 配合-x替换多次

xargs -I %  grep -l http://%7 %
这两个%是配对 的?
作者: Edengundam    时间: 2007-03-16 14:59
手头没有FreeBSD...我也是看man帮你...你先看find的结果...
我那个不要用J用I试试...手头都是linux
作者: zhengwei_zw    时间: 2007-03-16 15:00
ns# find /home/user -name "*.php" | xargs -I % grep -l http://%7 %
正在find……
作者: Edengundam    时间: 2007-03-16 15:00
原帖由 zhengwei_zw 于 2007-3-16 14:58 发表

xargs -I %  grep -l http://%7 %
这两个%是配对 的?



使用%作为替换字符串...
你试试...手头没有环境, 很难测试
作者: zhengwei_zw    时间: 2007-03-16 15:01
应该可以,我找了个函数,一下就查到文件了。谢谢
作者: 一梦如是    时间: 2007-03-16 15:01
  1. -I {}
复制代码

加个空格试试
作者: zhengwei_zw    时间: 2007-03-16 15:21
xargs: unterminated quote
好象确实有问题
作者: Edengundam    时间: 2007-03-16 15:27
原帖由 zhengwei_zw 于 2007-3-16 15:21 发表
xargs: unterminated quote
好象确实有问题



你可以先find然后生成一个文件. 然后一段一段的去  xargs

或者看看, 也许有帮助

-L number
             Call utility for every number lines read.        If EOF is reached and
             fewer lines have been read than number then utility will be
             called with the available lines.

-n number
             Set the maximum number of arguments taken from standard input for
             each invocation of utility.  An invocation of utility will use
             less than number standard input arguments if the number of bytes
             accumulated (see the -s option) exceeds the specified size or
             there are fewer than number arguments remaining for the last
             invocation of utility.  The current default value for number is
             5000.
作者: dradhzn    时间: 2007-03-16 23:01
find . -name "*.htm" -exec grep -l "ffmail" {} \;




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2