简体   繁体   中英

Linux Command line Help | extract specific parts from file

Suppose I have a log which has data in the format given below

        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 

I want to extract the numbers having success status. Is there any way in linux using command line(grep, sed) to extract the data as mentioned. ?? Thanks all ..

grep only solution:

grep -Po '\d+(?= success)' file

or with awk only :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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