grep - grep 命令输出,但如何查找特定块?
问题描述
我正在寻找一些带有 grep 的特定块
例如,我有来自 android 设备的输出:
Stream volumes (device: index)
- STREAM_VOICE_CALL:
Muted: false
Min: 1
Max: 5
Current: 40000000 (default): 4
Devices: earpiece
- STREAM_SYSTEM:
Muted: false
Min: 0
Max: 7
Current: 40000000 (default): 5
Devices: speaker
- STREAM_RING:
Muted: false
Min: 0
Max: 7
Current: 40000000 (default): 5
Devices: speaker
**- STREAM_MUSIC:
Muted: false
Min: 0
Max: 15
Current: 2 (speaker): 12, 4000000 (usb_headset): 3, 40000000 (default): 8
Devices: speaker**
- STREAM_ALARM:
Muted: false
Min: 0
Max: 7
Current: 40000000 (default): 6
Devices: speaker
- STREAM_NOTIFICATION:
Muted: false
Min: 0
Max: 7
Current: 40000000 (default): 5
Devices: speaker
- STREAM_BLUETOOTH_SCO:
Muted: false
Min: 0
Max: 15
Current: 40000000 (default): 7
Devices: earpiece
- STREAM_SYSTEM_ENFORCED:
Muted: false
Min: 0
Max: 7
Current: 40000000 (default): 5
Devices: speaker
- STREAM_DTMF:
Muted: false
Min: 0
Max: 15
Current: 40000000 (default): 11
Devices: speaker
- STREAM_TTS:
Muted: false
Min: 0
Max: 15
Current: 2 (speaker): 12, 4000000 (usb_headset): 3, 40000000 (default): 8
Devices: speaker
- STREAM_ACCESSIBILITY:
Muted: false
Min: 0
Max: 15
Current: 2 (speaker): 12, 4000000 (usb_headset): 3, 40000000 (default): 8
Devices: speaker
我需要使用 grep 获取 ** ** 中的块,我需要哪个代码 grep 命令来找到特定的输出块?我试过了
adb shell dumpsys 音频| grep {STREAM_MUSIC:,STREAM_ALARM} 并且不返回任何内容 adb shell dumpsys audio | grep -w STREAM_MUSIC 只返回第一行
解决方案
如果你可以使用awk
,你可以这样做:
awk '/- STREAM/ {f=0} /- STREAM_MUSIC:/ {f=1} f'
- STREAM_MUSIC:
Muted: false
Min: 0
Max: 15
Current: 2 (speaker): 12, 4000000 (usb_headset): 3, 40000000 (default): 8
Devices: speaker
推荐阅读
- c# - 使用LINQ的c#列表中两个数字之间的元素
- javascript - Why does awaiting Selenium getAttribute still return a promise?
- javascript - Index of object in array which has array of one object
- python - 更改 xlswriter python pandas 中行的位置
- ios - Swift 5.1 和 Alamofire 5.1:GET 方法错误
- api - 从 Kubernetes Pod 内部为 API Metric Server 使用 cURL
- php - Javascript没有以AJAX MODAL形式获取变量的值
- flutter - 仅在页面重建或应用程序重新加载时才加载数据 - 提供者
- flutter - 如何将带有子目录的目录/文件夹复制到另一个位置?
- unity3d - 2个统一对象的脚本可以获取彼此的变量吗?{已回答}