当前位置: 技术问答>linux和unix
shell里怎么用正则表达式取子串
来源: 互联网 发布时间:2017-03-10
本文导语: 比如从以下字符串中取出rtmpte://rhapsodyev-159.fcod.llnwd.net/a4376/v1/s/9/5/1/9/1/384419159?e=1345174409&h=ee604ab75c6577196ae4d3dd1ef27b6c中的rtmpte://rhapsodyev-159.fcod.llnwd.net/a4376/v1/s/9/5/1/9/1/384419159?e=1345174409&,有什么好方法,grep,sed,awk都...
比如从以下字符串中取出rtmpte://rhapsodyev-159.fcod.llnwd.net/a4376/v1/s/9/5/1/9/1/384419159?e=1345174409&h=ee604ab75c6577196ae4d3dd1ef27b6c中的rtmpte://rhapsodyev-159.fcod.llnwd.net/a4376/v1/s/9/5/1/9/1/384419159?e=1345174409&,有什么好方法,grep,sed,awk都行,越简单越好!
RHAPSODY_TOGO128mp3 640g.115Poprtmpte://rhapsodyev-159.fcod.llnwd.net/a4376/v1/s/9/5/1/9/1/384419159?e=1345174409&h=ee604ab75c6577196ae4d3dd1ef27b6c1345173808914:jason-huo@rhapsody.com:40134:rn_popoutNORMALtrackhttp://mp3.rhapsody.com/goto?rcid=Tra.30867607&pcode=rn&addToCart=Tra.308676070http://static.rhap.com/img/170x170/3/1/6/9/2279613_170x170.jpgAlb.308489990falseThe Fame MonsterEditedThe Fame Monster1falseLady GaGaArt.20067373Dance Pop200933594lady-gaga/the-fame-monsterAlb.30848999Art.20067373Lady Gaga33594lady-gagaArt.200673731The Fame MonsterLady Gagag.115Popg.290Poker Face237trackhttp://mp3.rhapsody.com/goto?rcid=Tra.30867607&pcode=rn&addToCart=Tra.3086760733338http://listen.vo.llnwd.net/g1/5/1/2/9/1/384419215.mp3Tra.3086760712truetruefalseg1bS=fAxjQCKKudM8GX8dsjzzBQVWnVUtrue
RHAPSODY_TOGO128mp3 640g.115Poprtmpte://rhapsodyev-159.fcod.llnwd.net/a4376/v1/s/9/5/1/9/1/384419159?e=1345174409&h=ee604ab75c6577196ae4d3dd1ef27b6c1345173808914:jason-huo@rhapsody.com:40134:rn_popoutNORMALtrackhttp://mp3.rhapsody.com/goto?rcid=Tra.30867607&pcode=rn&addToCart=Tra.308676070http://static.rhap.com/img/170x170/3/1/6/9/2279613_170x170.jpgAlb.308489990falseThe Fame MonsterEditedThe Fame Monster1falseLady GaGaArt.20067373Dance Pop200933594lady-gaga/the-fame-monsterAlb.30848999Art.20067373Lady Gaga33594lady-gagaArt.200673731The Fame MonsterLady Gagag.115Popg.290Poker Face237trackhttp://mp3.rhapsody.com/goto?rcid=Tra.30867607&pcode=rn&addToCart=Tra.3086760733338http://listen.vo.llnwd.net/g1/5/1/2/9/1/384419215.mp3Tra.3086760712truetruefalseg1bS=fAxjQCKKudM8GX8dsjzzBQVWnVUtrue
|
$ grep -o "rtmpte[^;]+" log.txt
rtmpte://rhapsodyev-159.fcod.llnwd.net/a4376/v1/s/9/5/1/9/1/384419159?e=1345174409&
rtmpte://rhapsodyev-159.fcod.llnwd.net/a4376/v1/s/9/5/1/9/1/384419159?e=1345174409&
|
$ sed -n 's/.*(rtmpte[^;]+).*/1/p' log.txt
rtmpte://rhapsodyev-159.fcod.llnwd.net/a4376/v1/s/9/5/1/9/1/384419159?e=1345174409&
rtmpte://rhapsodyev-159.fcod.llnwd.net/a4376/v1/s/9/5/1/9/1/384419159?e=1345174409&