Issue
I'm looking for some specific block with grep
for example I have this output from android device:
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
I need to get the block within ** ** with grep, which code grep command do I need to find that specific block of output? I've tried with
adb shell dumpsys audio | grep {STREAM_MUSIC:,STREAM_ALARM} and returns nothing adb shell dumpsys audio | grep -w STREAM_MUSIC returns only the first line
Solution
If you can use awk
, you can do this:
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
Answered By - Jotne Answer Checked By - Clifford M. (WPSolving Volunteer)