0

hi i want the date and time of the following content

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

i used the following command but unable to finish it because the date is starting with single number 4 instead of 04

grep -Eo '\w{3} \w{3} '
codeforester
  • 28,846
  • 11
  • 78
  • 104
Thiru
  • 181
  • 1
  • 1
  • 6

1 Answers1

1

With GNU grep:

echo "text text Sat Mar  4 12:13:23 IST 2017 text text blah:blah" | grep -Eo '[^ ]{3} [^ ]{3} [0-9 ]{2} [0-9:]{7,8} [^ ]+ [0-9]{4}'

Output:

Sat Mar  4 12:13:23 IST 2017

Reference: The Stack Overflow Regular Expressions FAQ

Community
  • 1
  • 1
Cyrus
  • 69,405
  • 13
  • 65
  • 117