Hi, guys, I didn't find a solution with grep, but found workrounds with tr and sed. May these help.
First I want to make it clear that while [0-9][0-9][0-9][0-9] works quite well, [0-9]{4} do the same job.
As in the "tr" case, I tried
Code:
echo "It is now 2130 its time to begin" | tr -d [[:alpha:]] | tr -d " "
It works.
I have been learning the powerfull sed these days, so I gave it a try:
Code:
echo "It is now 2130 its time to begin" | sed 's/ /\n/g' | grep -E [0-9]{4}
The sed command here replace whitespace with a ...... hmmm, line terminator ( Sorry, I am not sure about the right jargon. lol ), thus place every word in a seperate line.
BTW, I found the first line of grep manual is " grep , egrep, fgrep, rgrep, - print lines matching a pattern". So maybe it print "lines" instead of specified words in lines in my humble opion.