Info
I have a string that has time info in it. I need to get only the number of months from this string. I'm trying to accomplish this using sed
, but I haven't had too much luck yet. Using bash + command line tools is a requirement for me.
Current attempt
echo "1969 years 12 months 25 days 19 hours 38 minutes 24 seconds since last release" | sed -r "s/^([0-9]+).*/\1/"
returns 1969
Bonus
More generally, my problem is the entire "1969 years 12 months"
portion of the string. I'm using date
to get a time differential but I have to account for the 1970 start date. I find it odd that my current output expresses 1970 as 1969 year and 12 months
.
Edit: I'm attempting to use nunk's solution from this post:
It works fine for everything, except for the months. The quantity of months is off by (12-printed number of months).