首页 > 解决方案 > 在 2 条不同的行上搜索 2 种不同的图案并将它们打印在一行中?

问题描述

我有这样的文件 (1),我想要这样的输出 (2)。使用“grep -e file -e index”我得到了这个(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
...

标签: grep

解决方案


如果它总是每隔一行,paste就会这样做:

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

推荐阅读