Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.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
Sorting 使用模式文件进行grep和排序_Sorting_Batch File_Cmd_Grep - Fatal编程技术网

Sorting 使用模式文件进行grep和排序

Sorting 使用模式文件进行grep和排序,sorting,batch-file,cmd,grep,Sorting,Batch File,Cmd,Grep,我有两个txt文件:patterns.txt和fulldb.txt 我想输出fulldb.txt的行,其中包含patterns.txt中的一行,因此我要: fgrep -f patterns.txt fulldb.txt > output.txt 这很有效 但是现在我想让输出按照patterns.txt中的顺序排序。我可以做到: copy /y NUL output_sorted.txt > NUL for /F "tokens=*" %%J in (patterns.txt) d

我有两个txt文件:patterns.txt和fulldb.txt

我想输出fulldb.txt的行,其中包含patterns.txt中的一行,因此我要:

fgrep -f patterns.txt fulldb.txt > output.txt
这很有效

但是现在我想让输出按照patterns.txt中的顺序排序。我可以做到:

copy /y NUL output_sorted.txt > NUL
for /F "tokens=*" %%J in (patterns.txt) do (
    fgrep "%%J" fulldb.txt >> output_sorted.txt
)
但当文件足够大时,这在运行时需要花费太多时间

有更好的解决办法吗


谢谢

我看到你在使用cmd,但你在评论中说bash解决方案对你来说很好

以下可能会起作用:


阅读pat时
;执行fgrep“${pat}”fulldb.txt>>输出\u sorted.txt;完成

您是否尝试运行完整的grep(您的第一个代码)生成临时文件,然后针对临时文件而不是fulldb运行部分grep(第二个代码)?@mikedu95您有fgrep,但您也有shell?用bash编写脚本更容易。谢谢你。我在Windows下,所以我使用cmd来编写脚本。使用bash而不是cmd有更好的解决方案吗?因为如果bash工作得更好,我也可以使用它。