의 출력에서 pactl list sink-inputs
다음을 가져와야 합니다.수신기 입력VLC 번호. 그 전에는 VLC 출력만 포함된 부분을 추출해 보았습니다. 내가 생각하는 모든 방법에는 단점이 있습니다. 다음은 샘플 출력입니다.
$ pactl list sink-inputs
Sink Input #1373
Driver: protocol-native.c
Owner Module: 9
Client: 10350
Sink: 0
Sample Specification: float32le 2ch 44100Hz
Channel Map: front-left,front-right
Format: pcm, format.sample_format = "\"float32le\"" format.rate = "44100" format.channels = "2" format.channel_map = "\"front-left,front-right\""
Corked: no
Mute: no
Volume: 0: 100% 1: 100%
0: 0,00 dB 1: 0,00 dB
balance 0,00
Buffer Latency: 453287 usec
Sink Latency: 19697 usec
Resample method: copy
Properties:
media.role = "video"
media.name = "audio stream"
application.name = "VLC media player (LibVLC 2.1.5)"
native-protocol.peer = "UNIX socket client"
native-protocol.version = "28"
application.id = "org.VideoLAN.VLC"
application.version = "2.1.5"
application.icon_name = "vlc"
application.language = "pt_BR.UTF-8"
application.process.id = "19965"
application.process.machine_id = "948146522454ae6aa2bb8ed153f4bce4"
application.process.session_id = "948146522454ae6aa2bb8ed153f4bce4-1431635199.85146-1790309877"
application.process.user = "teresaejunior"
application.process.host = "localhost"
application.process.binary = "vlc"
window.x11.display = ":0.0"
module-stream-restore.id = "sink-input-by-media-role:video"
Sink Input #1378
Driver: protocol-native.c
Owner Module: 9
Client: 10378
Sink: 0
Sample Specification: s16le 2ch 44100Hz
Channel Map: front-left,front-right
Format: pcm, format.sample_format = "\"s16le\"" format.rate = "44100" format.channels = "2" format.channel_map = "\"front-left,front-right\""
Corked: no
Mute: no
Volume: 0: 87% 1: 87%
0: -3,63 dB 1: -3,63 dB
balance 0,00
Buffer Latency: 989841 usec
Sink Latency: 19572 usec
Resample method: n/a
Properties:
media.name = "audio stream"
application.name = "mplayer2"
native-protocol.peer = "UNIX socket client"
native-protocol.version = "28"
application.process.id = "20093"
application.process.user = "teresaejunior"
application.process.host = "localhost"
application.process.binary = "mplayer2"
application.language = "C"
window.x11.display = ":0.0"
application.process.machine_id = "948146522454ae6aa2bb8ed153f4bce4"
module-stream-restore.id = "sink-input-by-application-name:mplayer2"
둘 다 출력이 끝날 때까지 VLC 부분뿐만 아니라 mplayer2 부분도 awk '/^Sink/,/VLC/'
가져옵니다 .sed -n '/^Sink/,/VLC/p'
$ pactl list sink-inputs | awk '/^Sink/,/VLC/'
Sink Input #1373
Driver: protocol-native.c
Owner Module: 9
Client: 10350
Sink: 0
Sample Specification: float32le 2ch 44100Hz
Channel Map: front-left,front-right
Format: pcm, format.sample_format = "\"float32le\"" format.rate = "44100" format.channels = "2" format.channel_map = "\"front-left,front-right\""
Corked: no
Mute: no
Volume: 0: 100% 1: 100%
0: 0,00 dB 1: 0,00 dB
balance 0,00
Buffer Latency: 437414 usec
Sink Latency: 19666 usec
Resample method: copy
Properties:
media.role = "video"
media.name = "audio stream"
application.name = "VLC media player (LibVLC 2.1.5)"
Sink Input #1379
Driver: protocol-native.c
Owner Module: 9
Client: 10381
Sink: 0
Sample Specification: s16le 2ch 44100Hz
Channel Map: front-left,front-right
Format: pcm, format.sample_format = "\"s16le\"" format.rate = "44100" format.channels = "2" format.channel_map = "\"front-left,front-right\""
Corked: no
Mute: no
Volume: 0: 87% 1: 87%
0: -3,63 dB 1: -3,63 dB
balance 0,00
Buffer Latency: 980045 usec
Sink Latency: 19563 usec
Resample method: n/a
Properties:
media.name = "audio stream"
application.name = "mplayer2"
native-protocol.peer = "UNIX socket client"
native-protocol.version = "28"
application.process.id = "20093"
application.process.user = "teresaejunior"
application.process.host = "localhost"
application.process.binary = "mplayer2"
application.language = "C"
window.x11.display = ":0.0"
application.process.machine_id = "948146522454ae6aa2bb8ed153f4bce4"
module-stream-restore.id = "sink-input-by-application-name:mplayer2"
grep -Poz '^Sink(?s).*?VLC'
작동하지만 VLC 출력이 mplayer2 이후여야 하는 경우 실패합니다(VLC 대신 mplayer2로 테스트).
$ pactl list sink-inputs | grep -Poz '^Sink(?s).*?mplayer'
Sink Input #1373
Driver: protocol-native.c
Owner Module: 9
Client: 10350
Sink: 0
Sample Specification: float32le 2ch 44100Hz
Channel Map: front-left,front-right
Format: pcm, format.sample_format = "\"float32le\"" format.rate = "44100" format.channels = "2" format.channel_map = "\"front-left,front-right\""
Corked: no
Mute: no
Volume: 0: 100% 1: 100%
0: 0,00 dB 1: 0,00 dB
balance 0,00
Buffer Latency: 441088 usec
Sink Latency: 18159 usec
Resample method: copy
Properties:
media.role = "video"
media.name = "audio stream"
application.name = "VLC media player (LibVLC 2.1.5)"
native-protocol.peer = "UNIX socket client"
native-protocol.version = "28"
application.id = "org.VideoLAN.VLC"
application.version = "2.1.5"
application.icon_name = "vlc"
application.language = "pt_BR.UTF-8"
application.process.id = "19965"
application.process.machine_id = "948146522454ae6aa2bb8ed153f4bce4"
application.process.session_id = "948146522454ae6aa2bb8ed153f4bce4-1431635199.85146-1790309877"
application.process.user = "teresaejunior"
application.process.host = "localhost"
application.process.binary = "vlc"
window.x11.display = ":0.0"
module-stream-restore.id = "sink-input-by-media-role:video"
Sink Input #1380
Driver: protocol-native.c
Owner Module: 9
Client: 10396
Sink: 0
Sample Specification: s16le 2ch 44100Hz
Channel Map: front-left,front-right
Format: pcm, format.sample_format = "\"s16le\"" format.rate = "44100" format.channels = "2" format.channel_map = "\"front-left,front-right\""
Corked: no
Mute: no
Volume: 0: 87% 1: 87%
0: -3,63 dB 1: -3,63 dB
balance 0,00
Buffer Latency: 989841 usec
Sink Latency: 18084 usec
Resample method: n/a
Properties:
media.name = "audio stream"
application.name = "mplayer
원하는 출력:
Sink Input #1373
Driver: protocol-native.c
Owner Module: 9
Client: 10350
Sink: 0
Sample Specification: float32le 2ch 44100Hz
Channel Map: front-left,front-right
Format: pcm, format.sample_format = "\"float32le\"" format.rate = "44100" format.channels = "2" format.channel_map = "\"front-left,front-right\""
Corked: no
Mute: no
Volume: 0: 100% 1: 100%
0: 0,00 dB 1: 0,00 dB
balance 0,00
Buffer Latency: 441088 usec
Sink Latency: 18159 usec
Resample method: copy
Properties:
media.role = "video"
media.name = "audio stream"
application.name = "VLC media player (LibVLC 2.1.5)"
답변1
그리고 ed
:
ed -s <<'IN'
r !pactl list sink-inputs
/VLC/+,$d
?Sink Input?,.p
q
IN
r
명령 출력을 텍스트 버퍼에 기록하고 첫 d
번째 줄 match 이후의 모든 항목을 제거한 VLC
다음 p
이전 줄에서 Sink Input
현재 줄까지 일치시킵니다.
그리고 sed
:
pactl list sink-inputs | sed -n 'H;/Sink Input/h;/VLC/{x;p;q}'
각 라인을 이전 버퍼에 추가하고 H
, 라인이 일치하면 이전 버퍼를 Sink Input
덮어쓰고 h
, 라인이 VLC와 일치하면 x
예약된 공간 w를 변경합니다. 패턴 공간, p
rins 및 q
uits.
답변2
저는 Perl의 단락 모드를 사용하겠습니다:
pactl list sink-inputs | perl -00ne 'print if s/(.*?VLC.*?\n).*/$1/ms'
-00
입력 레코드 구분 기호를 \n\n
단락인 "행" 으로 설정합니다 . 그런 다음 교체는 첫 번째 줄 이전의 모든 항목과 일치하고 VLC
첫 번째 개행 이전의 모든 항목을 일치시키고 $1
그 이후의 모든 항목은 삭제됩니다(모든 항목을 로 바꾸었기 때문입니다 $1
). 마지막으로 교체가 성공한 "줄"을 인쇄합니다.
답변3
이는 실제로 빈 줄로 구분된 여러 줄의 레코드입니다. Awk는 이런 종류의 데이터 작업에 적합합니다.
pactl list sink-inputs | awk -v RS="" '/VLC/'
첫 번째 "VLC" 등장 후 레코드의 하단 부분을 포함하지 않는 것에 대해 매우 까다롭게 설정하려면 다음을 수행하세요.
pactl list sink-inputs | awk -v RS="" -v FS="\n" '/VLC/{ for(i=1; i<=NF; i++) { print $i; if($i ~ /VLC/) exit}}'