Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
grep是一个命令输出,但是如何查找特定的块呢?_Grep - Fatal编程技术网

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

grep是一个命令输出,但是如何查找特定的块呢?,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: 4000

我在找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 audio | 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

谢谢,非常有用,但这在grep中不可能吗?@EdgarL并非所有工具都能完成所有任务
grep
擅长查找内容,
awk
擅长处理多行。我发现使用adb shell dumpsys audio | grep-A 5流音乐我得到了相同的结果