Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 将带有模式的“grep-v”从多个文件应用到多个文件_Bash_Shell_Grep - Fatal编程技术网

Bash 将带有模式的“grep-v”从多个文件应用到多个文件

Bash 将带有模式的“grep-v”从多个文件应用到多个文件,bash,shell,grep,Bash,Shell,Grep,我有很多文件,比如1.txt、2.txt等,还有1.search、2.search等 我如何在所有这些上使用一个grep-v,而不是每次都编写这样的命令 cat 1.txt | grep -f 1.search -v 及 我试过了 for i in 1..20 ; do grep -v -f /home/DAT/Desktop/Project/data/$i.search \ /home/DAT/Desktop/Project/input/$i.txt > \

我有很多文件,比如1.txt、2.txt等,还有1.search、2.search等

我如何在所有这些上使用一个grep-v,而不是每次都编写这样的命令

cat 1.txt | grep -f 1.search -v

我试过了

for i in 1..20 ; do
    grep -v -f /home/DAT/Desktop/Project/data/$i.search \
        /home/DAT/Desktop/Project/input/$i.txt > \
        /home/DAT/Desktop/Project/data/selection/$i.result.txt
done
但我有一个错误:

使用-F进行固定字符串搜索:


否则,grep会将通过-f指定的输入文件中的字符视为正则表达式。

这里不需要cat,只需执行grep-f 1.search-v 1.txt您搜索的字符串是否不同?对于1-2中的i;执行grep-v-f$i.search$i.txt;请不要在注释中添加代码。该错误表示其中一个*.search文件中的数据格式不正确。
for i in 1..20 ; do
    grep -v -f /home/DAT/Desktop/Project/data/$i.search \
        /home/DAT/Desktop/Project/input/$i.txt > \
        /home/DAT/Desktop/Project/data/selection/$i.result.txt
done
grep: Unmatched [ or [^ 
for i in {1..20} ; do
    grep -vFf /home/DAT/Desktop/Project/data/$i.search \
        /home/DAT/Desktop/Project/input/$i.txt > \
        /home/DAT/Desktop/Project/data/selection/$i.result.txt
done