1

我想使用 shell 脚本将以下 GST 命令分成两半。

/GstPipeline:pipeline0/GstUDPSink:udpsink0.GstPad:sink: caps = application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, sprop-parameter-sets=(string)\"Z0KAHukBQHpCAAAH0AAB1MAI\\,aM48gA\\=\\=\", payload=(int)96, ssrc=(uint)2416890621, clock-base=(uint)518578781, seqnum-base=(uint)24075

拆分必须发生在 caps = 两个新行应该存储在两个变量 $var1 和 $var2

$var1 应该包含 /GstPipeline:pipeline0/GstUDPSink:udpsink0.GstPad:sink:

并且 $var2 应该包含 application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, sprop-parameter-sets=(string)\"Z0KAHukBQHpCAAAH0AAB1MAI\\,aM48gA\\=\\=\", payload=(int)96, ssrc=(uint)2416890621, clock-base=(uint)518578781, seqnum-base=(uint)24075

请记住,输入字符串中有两个反斜杠。所以做一个回声只会给出一个反斜杠。

4

2 回答 2

1
a="/GstPipeline:pipeline0/GstUDPSink:udpsink0.GstPad:sink: caps = application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, sprop-parameter-sets=(string)\"Z0KAHukBQHpCAAAH0AAB1MAI\\,aM48gA\\=\\=\", payload=(int)96, ssrc=(uint)2416890621, clock-base=(uint)518578781, seqnum-base=(uint)24075"

你可以用空格来切割字符串。

var1=`echo $a | cut -d' ' -f1` 

$var1 = /GstPipeline:pipeline0/GstUDPSink:udpsink0.GstPad:sink:

var2=`echo $a | cut -d' ' -f4-` 

$var2 = application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, sprop-parameter-sets=(string)\"Z0KAHukBQHpCAAAH0AAB1MAI\\,aM48gA\\=\\=\", payload=(int)96, ssrc=(uint)2416890621, clock-base=(uint)518578781, seqnum-base=(uint)24075
于 2013-02-10T11:55:14.187 回答
1

使用shell 参数扩展

$ cmd='/GstPipeline:pipeline0/GstUDPSink:udpsink0.GstPad:sink: caps = application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, sprop-parameter-sets=(string)\"Z0KAHukBQHpCAAAH0AAB1MAI\\,aM48gA\\=\\=\", payload=(int)96, ssrc=(uint)2416890621, clock-base=(uint)518578781, seqnum-base=(uint)24075'

$ first=${cmd% caps = *}; echo ">>$first<<"
>>/GstPipeline:pipeline0/GstUDPSink:udpsink0.GstPad:sink:<<

$ second=${cmd#* caps = }; echo ">>$second<<"
>>application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)H264, sprop-parameter-sets=(string)\"Z0KAHukBQHpCAAAH0AAB1MAI\\,aM48gA\\=\\=\", payload=(int)96, ssrc=(uint)2416890621, clock-base=(uint)518578781, seqnum-base=(uint)24075<<
于 2013-02-10T12:19:00.000 回答