grep命令输出,但是如何查找特定的块?

时间:2019-09-30 15:17:14

标签: 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音频| grep -w STREAM_MUSIC   仅返回第一行

1 个答案:

答案 0 :(得分:0)

如果可以使用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