日期:2014-05-16  浏览次数:20707 次

shell里怎么用正则表达式取子串
比如从以下字符串中取出<mediaUrl type="string">rtmpte://rhapsodyev-159.fcod.llnwd.net/a4376/v1/s/9/5/1/9/1/384419159?e=1345174409&amp;h=ee604ab75c6577196ae4d3dd1ef27b6c</mediaUrl>中的rtmpte://rhapsodyev-159.fcod.llnwd.net/a4376/v1/s/9/5/1/9/1/384419159?e=1345174409&amp,有什么好方法,grep,sed,awk都行,越简单越好!


<?xml version="1.0" encoding="UTF-8"?>
<o><data class="object"><accountType type="string">RHAPSODY_TOGO</accountType><bitRate type="number">128</bitRate><format type="string">mp3 64</format><freePlaysRemaining type="number">0</freePlaysRemaining><genre class="object"><genreId type="string">g.115</genreId><name type="string">Pop</name><rootGenreName type="string"/></genre><mediaUrl type="string">rtmpte://rhapsodyev-159.fcod.llnwd.net/a4376/v1/s/9/5/1/9/1/384419159?e=1345174409&amp;h=ee604ab75c6577196ae4d3dd1ef27b6c</mediaUrl><playbackSessionId type="string">1345173808914:jason-huo@rhapsody.com:40134:rn_popout</playbackSessionId><playbackType type="string">NORMAL</playbackType><purchaseInfo class="object"><type type="string">track</type><url type="string">http://mp3.rhapsody.com/goto?rcid=Tra.30867607&amp;pcode=rn&amp;addToCart=Tra.30867607</url></purchaseInfo><radVersion type="number">0</radVersion><track class="object"><album class="object"><albumArt162X162Url type="string">http://static.rhap.com/img/170x170/3/1/6/9/2279613_170x170.jpg</albumArt162X162Url><albumArt70X70Url type="string"/><albumId type="string">Alb.30848999</albumId><albumType type="number">0</albumType><compilation type="boolean">false</compilation><copyright type="string"/><displayName type="string">The Fame Monster</displayName><displayableAlbumTypes class="array"><e type="string">Edited</e></displayableAlbumTypes><label type="string"/><name type="string">The Fame Monster</name><numberOfDiscs type="string">1</numberOfDiscs><parentalAuthority type="boolean">false</parentalAuthority><primaryArtistDisplayName type="string">Lady GaGa</primaryArtistDisplayName><primaryArtistId type="string">Art.20067373</primaryArtistId><primaryStyle type="string">Dance Pop</primaryStyle><releaseYear type="string">2009</releaseYear><rightFlags type="number">33594</rightFlags><shortcut type="string">lady-gaga/the-fame-monster</shortcut><tracks class="array"/></album><albumId type="string">Alb.30848999</albumId><artist class="object"><artistId type="string">Art.20067373</artistId><genre class="object" null="true"/><imageURL type="string"/><name type="string">Lady Gaga</name><rightFlags type="number">33594</rightFlags><shortcut type="string">lady-gaga</shortcut></artist><artistId type="string">Art.20067373</artistId><blurbs class="array"/><discIndex type="string">1</discIndex><displayAlbumName type="string">The Fame Monster</displayAlbumName><displayArtistName type="string">Lady Gaga</displayArtistName><genre class="object"