I need to swap characters of a string (which is mmddyyyy format) and rearrange them in yyyymmdd. This string is obtained from a file name (abc_def_08032011.txt).
string=$(ls abc_def_08032011.txt | awk '{print substr($0,9,8)}')
For example:
- Current string:
08032011(This may not necessarily be the current date) - Desired string:
20110803
I tried split function, but it won't work since the string does not have any delimiter.
Any ideas/suggestions greatly appreciated.