2021年9月2日木曜日

Grep 一致した部分だけ抽出する

sample.logファイル内から、/数字8桁/だけ抜き出したい。

以下のコマンドでは一致する行がすべて表示されてしまう。

$ grep -E "\/[0-9]{8}\/" sample.log

↓出力結果

・・・remote.php/webdav/110015/index.php/apps/files/・・・

・・・remote.php/webdav/201013/index.php/apps/files/・・・

・・・remote.php/webdav/301021/index.php/apps/files/・・・

・・・remote.php/webdav/601001/index.php/apps/files/・・・

・・・remote.php/webdav/701005/ index.php/apps/files/・・・


 -oオプションを使う

$ grep -Eo "\/[0-9]{8}\/" sample.log

↓出力結果

/110015/

/201013/

/301021/

/601001/

/701005/ 



0 件のコメント:

コメントを投稿