在2条不同的线上搜索2种不同的图案并将它们打印在一行中?

时间:2019-01-03 16:07:23

标签: grep

我有一个像这样的文件(1),我想要一个像这样的输出(2)。通过“ grep -e文件-e索引”,我得到了这个(3)。您知道实现(2)中的结构缺少什么吗?

(1)

file: path/to/file1
other info_1
index = a
file: path/to/file2
other info_2
index = b
file: path/to/file3
other info_3
index = c
...

(2)

file: path/to/file1 index = a
file: path/to/file2 index = b
file: path/to/file3 index = c
...

(3)

file: path/to/file1 
index = a
file: path/to/file2 
index = b
file: path/to/file3 
index = c
...

1 个答案:

答案 0 :(得分:0)

如果总是每隔一行,paste将会执行:

grep -e file -e index infile | paste - -