Linux 关于solaris中的grep
我想在多个文件中的一个特定的工作格雷普。变量测试中存储了多个文件Linux 关于solaris中的grep,linux,shell,unix,Linux,Shell,Unix,我想在多个文件中的一个特定的工作格雷普。变量测试中存储了多个文件 TESTING=$(ls -tr *.txt) echo $TESTING test.txt ab.txt bc.txt grep "word" "$TESTING" grep: can't open test.txt ab.txt bc.txt 给我一个错误。除了for loop,还有其他方法吗?从$TESTING中去掉双引号 grep "word" $TESTING 双引号使整个文件列表扩展为单个参数,指向grep。正
TESTING=$(ls -tr *.txt)
echo $TESTING
test.txt ab.txt bc.txt
grep "word" "$TESTING"
grep: can't open test.txt
ab.txt
bc.txt
给我一个错误。除了for loop,还有其他方法吗?从
$TESTING
中去掉双引号
grep "word" $TESTING
双引号使整个文件列表扩展为单个参数,指向grep
。正确的方法是:
find . -name \*.txt -print0 | xargs -0 grep "word"
我想不需要引用
grep "word" $TESTING
适用于我(Ubuntu、bash)。你假设他想要在子目录中对文件进行grep。如果没有,那么我想你只能使用:grep word*.txt了。@pra,没错-肯定比他的方法要好。