grep - 在 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
...
解决方案
如果它总是每隔一行,paste
就会这样做:
grep -e file -e index infile | paste - -
推荐阅读
- imovie - iMovie 自动交叉淡入淡出音频
- vbscript - 获取带有空间错误的文件夹路径 - CreateObject ("Scripting.FileSystemObject")
- r - 与 zoo::rollapply 一起使用时 PerformanceAnalytics 包中的某些功能失败
- python-3.x - 找出一个子字符串是否包含在 Python 中的另一个字符串中
- ios - 如何防止 Firebase Cloud Messaging 在 iOS/Unity 上请求推送通知权限
- node.js - Axios http 调用的性能很差,调用需要更长的时间,导致每秒事务数减少
- c# - 从字符串中提取最新的日期时间
- python - 障碍物产生的距离太近
- windows - 我可以使用文件的最后提交时间作为 Windows 日期修改时间戳吗?
- json - 在json中添加换行符