Quote:
Originally Posted by StrongIce
Hi,
Linux newbie here trying to create a simple bash verification script.
I need help to parse this tring and put the date in a variable.
This line is from the 3rd line of a file.
VARIABLE_DATE 080612 08/06/2012 14:13:10
There are more spaces in between the values but I just need the
date 080612 so I can confirm it with the current system date
VDATE=`date '+%m%d%y'`.
Would greatly appreciate if someone could help.
|
Hi, something like the following could work for you to only get the date which in your case is '080612'.
Code:
# TEST='VARIABLE_DATE 080612 08/06/2012 14:13:10'
# echo ${TEST} | grep -Eo '[[:space:]]+[0-9]{6}[[:space:]]' | grep -Eo [0-9]{6}
080612
it will get the date only no matter how many spaces are there in between the values.
hope that helps