在文件数中查找字符串数 #/bin/ksh inputpath=“/home/beaadmin/SET4/Input.txt”#给出要搜索的模式 contentpath=“/home/beaadmin/SET4/FILES” outpath=“/home/beaadmin/SET4/impacted” 计数=1 读行时 做 回显“行:$count” 回音“$line” return=$(查找$contentpath-iname“*”| xargs grep“$line*”) 如果[$?-等式0] 然后 回显“$line”>>$outpath 其他的 回声“” fi 让计数=$count+1 完成

在文件数中查找字符串数 #/bin/ksh inputpath=“/home/beaadmin/SET4/Input.txt”#给出要搜索的模式 contentpath=“/home/beaadmin/SET4/FILES” outpath=“/home/beaadmin/SET4/impacted” 计数=1 读行时 做 回显“行:$count” 回音“$line” return=$(查找$contentpath-iname“*”| xargs grep“$line*”) 如果[$?-等式0] 然后 回显“$line”>>$outpath 其他的 回声“” fi 让计数=$count+1 完成,grep,find,xargs,Grep,Find,Xargs,假设我有string1,string2,string3和File1,File2,File3。。 我想在File1、File2、File3中查找string1,如果找到匹配项,则将其写入output dir。查找string2、string3的方法与查找string2、string3的方法相同。但是上面的代码没有找到它,假设string1、string2等。。。在Input.txt的不同行中,只有一个小错误 更改此项: #!/bin/ksh inputpath="/home/beaadmin/SE

假设我有string1,string2,string3和File1,File2,File3。。
我想在File1、File2、File3中查找string1,如果找到匹配项,则将其写入output dir。查找string2、string3的方法与查找string2、string3的方法相同。但是上面的代码没有找到它,假设string1、string2等。。。在Input.txt的不同行中,只有一个小错误

更改此项:

#!/bin/ksh
inputpath="/home/beaadmin/SET4/Input.txt" #Give patterns to be searched
contentpath="/home/beaadmin/SET4/FILES" 
outpath="/home/beaadmin/SET4/impacted"
 count=1 
while read line
 do
    echo "Line :$count"
    echo "$line"


    return=$(find $contentpath -iname "*" | xargs grep "$line*")

    if [ $? -eq 0 ]
    then
            echo "$line" >> $outpath
    else
            echo ""
    fi
    let count=$count+1

  done < $inputpath
为此:

xargs grep "$line*"
另外,还有两条关于
find
命令的建议。首先,
-iname“*”
没有任何效果。其次,您的
find
命令将查找一些目录,这将导致grep出现一些(可能是非致命的)错误。你可以用例如:

xargs grep "$line.*"

嗨,管理员/团队,以上帖子有什么更新吗?
find -type f $contentpath