Unix 一行一行地Grep一组文件?

Unix 一行一行地Grep一组文件?,unix,grep,command-line-interface,Unix,Grep,Command Line Interface,我有: ids,我要搜索的一组行,以及 type1\u数据,type2\u数据等,我要搜索的一组文件 如果我运行grep-f candidate\u ids type*,结果将以 type1 id_1 a type1 id_2 b type1 id_3 c type2 id_1 1 type2 id_2 2 type2 id_3 3 如何返回结果,使其看起来像 type1 id_1 a type2 id_1 1 type1 id_2 b type2 id_

我有:

ids
,我要搜索的一组行,以及

type1\u数据
type2\u数据
等,我要搜索的一组文件

如果我运行
grep-f candidate\u ids type*
,结果将以

type1  id_1  a
type1  id_2  b
type1  id_3  c
type2  id_1  1
type2  id_2  2
type2  id_3  3
如何返回结果,使其看起来像

type1  id_1  a
type2  id_1  1
type1  id_2  b
type2  id_2  2
type1  id_3  c
type2  id_3  3

??我可以编写脚本来解析结果,但如果可能的话,我更喜欢命令行方式。

您可以使用以下命令按第二个字段对结果进行排序:

grep -f candidate_ids type* | sort -k 2,2
“grep-f候选者ID type*| sort-k2,2”有效吗?