1

I'd like to split the following GST command into two halves using shell script.

/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

The split has to occur at caps = The two new lines should be stored in two variables $var1 and $var2

$var1 should contain /GstPipeline:pipeline0/GstUDPSink:udpsink0.GstPad:sink:

And $var2 should contain 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

Remember there are two backslashes in the input string. So doing an echo will give only one backslash.

2 Answers 2

1

Use 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<<
Sign up to request clarification or add additional context in comments.

2 Comments

When I do an echo, it changes the two backslashes to one backslash. How do I fix this? echo -e also gives me a single backslash.
make sure you use double quotes around the variable in the echo command. My output above was copy/pasted and the backslashes seem consistent.
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"

You could cut strings by spaces.

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

1 Comment

When I do an echo, it changes the two backslashes to one backslash. How do I fix this? echo -e also gives me a single backslash.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.