首页 \ 问答 \ 如何只用egrep返回部分行(How to return only part of a line with egrep)

如何只用egrep返回部分行(How to return only part of a line with egrep)

我有一个程序返回这样的内容:

status: playing
artURL: http://beta.grooveshark.com/static/amazonart/m3510922.jpg
estimateDuration: 29400
calculatedDuration: 293000
albumName: This Is It
position: 7291.065759637188
artistName: Michael Jackson
trackNum: 13
vote: 0
albumID: 3510922
songName: Billie Jean
artistID: 39
songID: 24684170

我期待从这一切中提取艺术家的名字和歌曲名称,我认为egrep会是一个很好的方式。 问题是我不知道如何只返回部分匹配行而不是整行。

egrep "artistName"显然返回

artistName: Michael Jackson

我只需要它回来

Michael Jackson

任何帮助,将不胜感激。 谢谢。


I have a program that returns something like this:

status: playing
artURL: http://beta.grooveshark.com/static/amazonart/m3510922.jpg
estimateDuration: 29400
calculatedDuration: 293000
albumName: This Is It
position: 7291.065759637188
artistName: Michael Jackson
trackNum: 13
vote: 0
albumID: 3510922
songName: Billie Jean
artistID: 39
songID: 24684170

I'm looking to extract the artist name and the song name from all this and I figured egrep would be a nice way to do it. The problem is that I have no idea how to return only part of the matching line and not the whole line.

egrep "artistName" obviously returns

artistName: Michael Jackson

I only need it to return

Michael Jackson

Any help would be appreciated. Thanks.


原文:https://stackoverflow.com/questions/3646682
更新时间:2023-06-21 16:06

最满意答案

您可以使用display:table属性如下:

#height-container{
    background:orange;
    display: table;
    vertical-align:top;
}

#left{
    display: table-cell;
    width:200px;
    background:#CD5555;
    padding:20px;
}

#right{
    width:600px;
    display: table-cell;
}

勾选此http://jsfiddle.net/6rBAw/2/

但它的工作,直到IE8及以上

已更新

CSS

#left{
    width:200px;
    background:#CD5555;
}

#right{
    float:right;
    width:600px;
}
.clr{clear:both;}

HTML

<div id='right'></div>
<div id='left'>
  <div class="clr"></div>
</div>

检查http://jsfiddle.net/6rBAw/4/


You can use display:table property for this:

#height-container{
    background:orange;
    display: table;
    vertical-align:top;
}

#left{
    display: table-cell;
    width:200px;
    background:#CD5555;
    padding:20px;
}

#right{
    width:600px;
    display: table-cell;
}

Check this http://jsfiddle.net/6rBAw/2/

But it's work till IE8 & above

UPDATED

CSS

#left{
    width:200px;
    background:#CD5555;
}

#right{
    float:right;
    width:600px;
}
.clr{clear:both;}

HTML

<div id='right'></div>
<div id='left'>
  <div class="clr"></div>
</div>

Check it http://jsfiddle.net/6rBAw/4/

相关问答

更多