2011-07-04 13 views
0

私はこのパターンを使用して4chanのスレッドのボード名を取得したい:sed -n s/pattern/ 1/p一致と不一致の両方を出力していますか?

echo $(cat ~/Desktop/test.html | sed -n "s/<title>\(.*\) - />\1</p") 

test.htmlというは含まれています

<link rel="shortcut icon" href="http://static.4chan.org/image/favicon.ico" /><link rel="stylesheet" type="text/css" href="http://static.4chan.org/css/yotsuba.9.css" title="Yotsuba"><link rel="alternate stylesheet" type="text/css" href="http://static.4chan.org/css/yotsublue.9.css" title="Yotsuba B"><link rel="alternate stylesheet" type="text/css" href="http://static.4chan.org/css/futaba.9.css" title="Futaba"><link rel="alternate stylesheet" type="text/css" href="http://static.4chan.org/css/burichan.9.css" title="Burichan"><title>/b/ - Random</title> 

のI/B /を一致させたいが、その代わりに、それは単に削除」 <title> "と" -」そうのような:

<link rel="shortcut icon" href="http://static.4chan.org/image/favicon.ico" /><link rel="stylesheet" type="text/css" href="http://static.4chan.org/css/yotsuba.9.css" title="Yotsuba"><link rel="alternate stylesheet" type="text/css" href="http://static.4chan.org/css/yotsublue.9.css" title="Yotsuba B"><link rel="alternate stylesheet" type="text/css" href="http://static.4chan.org/css/futaba.9.css" title="Futaba"><link rel="alternate stylesheet" type="text/css" href="http://static.4chan.org/css/burichan.9.css" title="Burichan">>/b/<Random</title> 

なぜ?

答えて

1

代理店にあなたが言ったことはすべてです。最初と最後から削除する場合は、両端を^$で固定し、その間のすべての文字を一致させる必要があります。

1

このような何か:。

sed -n "s/.*<title>\([^<>]*\) - .*/\1/p" ~/Desktop/test.html 

あなたの問題は、あなたの正規表現は、私の場合は、文字列(の先頭と一致していないということです*これを行う」との文字列の末尾(再度、私の場合には、それはです"。*"最後に)

関連する問題