Convert a a two digit year to four digits in bash
I have files in the format: test96abcd.TXT I am extracting the two digit year:
echo "test96abcd.TXT" | cut -c4-5
and I was hoping to do something like this:
echo "test96abcd.TXT" | cut -c4-5 | date +%Y
but it doesn't work, let alone I will have a ...Y2K problem (when it is 00, won't know if it is year 1900 or year 2000) although I can handle manually this exception with an "if 00 use 2000".
But is there a more elegant way to deal with this using t he 'date' command?
00s - how do you know if the dateXXshould EVER be20XXvs19XXor something else? if you just want to change everyXXto20XXthen you don't needdatefor that. Do your files always have 2 digits and only 2 digits in just 1 location or can you get files likefoo76bar83etc.txtorfoo1234bar.txtand if so how should they be handled? - Ed Morton