2016-12-21 6 views
1

シェルから部分文字列を抽出したい。これは一例です:bash内の部分文字列を取得する方法

[email protected]:~$ var=$(curl -s 'https://www.youtube.com/') 
[email protected]:~$ echo $var|grep -ob GetBrowse_rid 
[email protected]:~$ 50000:GetBrowse_rid 
[email protected]:~$ echo $var|grep -ob what_to_watch 
[email protected]:~$ 55555:what_to_watch 
[email protected]:~$ echo ${var:50000:55555} 

は、私が "GetBrowse_rid" と "what_to_watch" beetwenテキストを抽出したいのですが、何らかの理由で私のコードではない

+0

*それは何をするのですか、そうでなければ何を期待していましたか? – chepner

答えて

0

あなたが使用することができます動作しますsed

curl -s 'https://www.youtube.com/' | sed -n 's/.*\(GetBrowse_rid.*what_to_watch\).*/\1/p' 

GetBrowse_rid":"0xd43def10f9d14420","yt_fn":"what_to_watch 
+1

作品!!!!私はこれで2日失った。ありがとうございましたanubhava – mike

関連する問題