I have code where Im going through each row at a time and taking the 3rd column which is the date.
It echos the date in format 04-04-2017. Each row has a different date and I wish to take 5 years from that date and put it in the new variable dob_want2 but keep getting the error date:
invalid date ‘'04-04-2017' -5 years’
The file temp9_0.txt is in the format
123 5555 04-04-2017
126 1234 25-11-2014
218 0023 13-06-2002
and echo "$dob_want" outputs
04-04-2017
Its obviously not recognising $dob_want as a date. Any help suggestions on how I could treat this variable as a date would be much appreciated.
dob_want=$(head -1 temp9_0.txt | awk '{print $3}')
echo "$dob_want"
dob_want2=$(date +%d-%m-%y -d "$dob_want -5 years")
echo "$dob_want2"
datecan parse. See e.g. here.‘and’I suspect they come from inappropriate terminal translation of the message "ticks" rather then from the input data (I get the same using PuTTY with Win1252 instead of UTF-8). The real issue is thed-m-Y(or is itm-d-Y) format as @Kusalananda has already pointed out.‘and’are ticks that are included in the input data, which is wrongly encoded for the locale. (The OP includingecho "$dob_want"as already asked could help ascertain that.)datedoesn't provide any flexibility about the input format - newer versions ofbusybox datedo, as do thedateutilsutilities ex.dateutils.dadd -i '%d-%m-%Y' -f '%d-%m-%y' 04-04-2017 -5y