繁体   English   中英

Linux命令行帮助| 从文件中提取特定部分

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM