grep -E for linux date time string

时间:2017-03-04 07:00:14

标签: linux grep

您好我想要以下内容的日期和时间

"text text Sat Mar  4 12:13:23 IST 2017 text text blah:blah"

我使用了以下命令但无法完成它,因为日期是从单个数字4开始而不是04

grep -Eo '\w{3} \w{3} '

1 个答案:

答案 0 :(得分:1)

使用GNU grep:

What's your name? PM 2Ring
PM 2Ring enter a number: 50
Guess lower
PM 2Ring enter a number: 25
Guess higher
PM 2Ring enter a number: 37
Guess lower
PM 2Ring enter a number: 31
Guess higher
PM 2Ring enter a number: 34
Guess lower
PM 2Ring enter a number: 33
Guess lower
PM 2Ring enter a number: 32
You guessed 32 PM 2Ring, in 7 guesses
Play again? [y/N] y
PM 2Ring enter a number: 64
Guess lower
PM 2Ring enter a number: 32
Guess lower
PM 2Ring enter a number: 16
Guess higher
PM 2Ring enter a number: 24
Guess higher
PM 2Ring enter a number: 28
Guess lower
PM 2Ring enter a number: 26
You guessed 26 PM 2Ring, in 6 guesses
Play again? [y/N] n
Thanks for playing, PM 2Ring.

输出:

Sat Mar  4 12:13:23 IST 2017

参考:The Stack Overflow Regular Expressions FAQ