2013-02-10 114 views
1

我想使用shell腳本將以下GST命令分成兩部分。使用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

分裂具有帽發生= 這兩個新的線應儲存在兩個變量$ 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

請記住,輸入字符串中有兩個反斜槓。所以做一個回聲只會給一個反斜槓。

回答

1

使用shell parameter expansion

$ 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<< 
+0

當我做回聲時,它會將兩個反斜槓更改爲一個反斜槓。我該如何解決? echo -e也給我一個反斜槓。 – Maxtron 2013-02-10 13:56:41

+0

確保在echo命令中的變量周圍使用雙引號。我上面的輸出是複製/粘貼,反斜槓似乎一致。 – 2013-02-10 18:12:13

0
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 
+0

當我這樣做的回聲,它改變了兩個反斜槓反斜槓一個。我該如何解決? echo -e也給我一個反斜槓。 – Maxtron 2013-02-10 13:57:38