[英]Linux Command line Help | extract specific parts from file
假設我有一個日志,其中的數據格式如下
Time number status
2013-5-10 19:18:43.430 123456 success
2013-5-10 19:28:13.430 134324 fail
2013-5-10 19:58:33.430 456456 success
我想提取具有success
狀態的numbers
。 在Linux中,有什么方法可以使用命令行(grep,sed)來提取數據。 ?? 謝謝大家..
僅grep解決方案:
grep -Po '\d+(?= success)' file
或僅使用awk :
awk '$4=="success"&&$0=$3' input
cat file | grep success | awk '{print $3}'
你可以做
(grep 'success' | cut -d ' ' -f 3) <$file
這將根據成功狀態打印數字:
awk '$4 ~ /success/ {print $3}' logfile
使用perl:
perl -ne '/success/ && split && print "$_[2]\n"' inputfile
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.