2012/11/28

grep の -o オプションを使うとマッチした部分だけ列挙してくれる。
例えば <div>foo</div><div>bar</div>
<div>baz</div>
というテキストファイル foo.txt に対して grep -o "<div[^>]*>[^<]*<\/div>" foo.txt
と実行すると <div>foo</div>
<div>bar</div>
<div>baz</div>
が得られる。これを応用して echo 餃子の王将 | grep -o .
とやると




が得られる。

便利!!
Posted at 20:50 | WriteBacks () | Edit
Edit this entry...

wikieditish message: Ready to edit this entry.






















A quick preview will be rendered here when you click "Preview" button.