我有日誌文件中包含行:如何使用Linux CLI搜索文件中的模式?
07:44:24||||234.234.234.234|123.123.123.123|www.website.pl/some,site.html|a:0:{}
我如何獲得唯一www.website.pl/some,site.html
所有行?
這可以用「sed」或其他命令完成嗎?
我有日誌文件中包含行:如何使用Linux CLI搜索文件中的模式?
07:44:24||||234.234.234.234|123.123.123.123|www.website.pl/some,site.html|a:0:{}
我如何獲得唯一www.website.pl/some,site.html
所有行?
這可以用「sed」或其他命令完成嗎?
是的,用awk。
簡單地處理與
awk -F '|' '{print $7}'
小抄本文件上的示例行:
$ echo '07:44:24||||234.234.234.234|123.123.123.123|www.website.pl/some,site.html|a:0:{}' | awk -F '|' '{print $7}'
www.website.pl/some,site.html
CAVEAT這假設有在你的文件沒有其他管道除了那些用於delimters。
Cut還支持分隔符和字段選擇。
$ cut -d\| -f7
07:44:24||||234.234.234.234|123.123.123.123|www.website.pl/some,site.html|a:0:{}
www.website.pl/some,site.html
這可能會爲你工作:
echo '07:44:24||||234.234.234.234|123.123.123.123|www.website.pl/some,site.html|a:0:{}'|
sed 's/^\(\([^|]*\)|\)\{7\}.*/\2/'
www.website.pl/some,site.html
或者,如果網站都開始www
:
echo '07:44:24||||234.234.234.234|123.123.123.123|www.website.pl/some,site.html|a:0:{}'|
sed 's/.*\(www[^|]*\).*/\1/'
www.website.pl/some,site.html
完蛋了!謝謝 – Kamilos