我对正则表达式和sed/awk脚本不是很有经验。
我有类似于以下torrent url的url:
http://torcache.net/torrent/D7249CD9AF321C8578B3A7007ABBDD63B0475EEB.torrent?title=[kickass.to]against.the.ropes.by.carly.fall.epub.torrent我希望让、sed、或awk脚本在标题之后提取文本,即从上面的示例中提取文本:
kickass.toagainst.the.ropes.by.carly.fall.epub.torrent
发布于 2013-10-20 03:14:35
只需删除title=:sed 's/.*title=//'之前的所有内容
$ echo "http://torcache.net/torrent/D7249CD9AF321C8578B3A7007ABBDD63B0475EEB.torrent?title=[kickass.to]against.the.ropes.by.carly.fall.epub.torrent" | sed 's/.*title=//'
[kickass.to]against.the.ropes.by.carly.fall.epub.torrent发布于 2013-10-20 06:29:54
使用awk的一种简单方法:使用=作为字段分隔符:
awk -F"=" '{print $2}'因此:
echo "http://torcache.net/torrent/D7249CD9AF321C8578B3A7007ABBDD63B0475EEB.torrent?title=[kickass.to]against.the.ropes.by.carly.fall.epub.torrent" | awk -F"=" '{print $2}'
[kickass.to]against.the.ropes.by.carly.fall.epub.torrent发布于 2013-10-20 07:08:15
让我们说:
s='http://torcache.net/torrent/D7249CD9AF321C8578B3A7007ABBDD63B0475EEB.torrent?title=[kickass.to]against.the.ropes.by.carly.fall.epub.torrent'纯巴什溶液:
echo "${s/*title=}"
[kickass.to]against.the.ropes.by.carly.fall.epub.torrent使用grep -P**:**的或
echo "$s"|grep -oP 'title=\K.*'
[kickass.to]against.the.ropes.by.carly.fall.epub.torrenthttps://stackoverflow.com/questions/19473521
复制相似问题