Convert Zulu Format in Bash to MM/DD/YYYY

Though I found ID:20928993 which is promising but I need to do a little more than that kb item.


my format of the datastore is 20101022185123Z
where date = Oct 22, 2010 18hrs 51mins 23secs Zulu time
I need to construct a pipe sequence to count characters and rearrange formatting
to where this date will be represented as : MM/DD/YYYY

I know the correct format:: date +'%m/%d/%Y' == MM/DD/YYYY or 10/22/2010
If I could just output that I would but my stdin is 20101022185123Z

How do I convert it ?


I am not sure how to count characters. but once I do its some simple awk sequences I am sure...

logical goal steps:

for timestamp in myfile
do
        if timestamp!="";
        then
        YYYY = ""
        DD = ""
        MM = ""
     1) count/grep 0-3 L>R stdout characters print $1 assign to YYYY variable
     2) | count/grep 0-1 L>R stdout characters trim print $1 assign to MM variable
     3) | count/grep 0-1 L>R stdout characters trim print $1 assign to DD variable
     ##dump the rest of the string do not need mins nor seconds nor Zulu any more
else
# I want a blank if there is no timestamp
        YYYY = ""
        DD = ""
        MM = ""
fi
4) echo "$MM/$DD/$YYYY" > myfile.log

done    






thanks all in advance :)






JAaron AndersonProgramming Architect @ Widener UniversityAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

woolmilkporcCommented:
How about this for converting:

date -d "${timestamp:0:8}" +'%m/%d/%Y'

wmp


0
HeiniHogCommented:
DD=`echo $timestamp | sed -r "s|[0-9]{6}([0-9]{2}).*|\1|"`
MM=`echo $timestamp | sed -r "s|[0-9]{4}([0-9]{2}).*|\1|"`
YYYY=`echo $timestamp | sed -r "s|([0-9]{4}).*|\1|"`

that should do what you want
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
woolmilkporcCommented:
OK, to make your logic complete:

[[ ! -n $timestamp ]] && echo $(date -d "${timestamp:0:8}" +"%m/%d/%Y") >> myfile.log
0
woolmilkporcCommented:
.. sorry, typo as always:

[[ -n $timestamp ]] && echo $(date -d "${timestamp:0:8}"  +"%m/%d/%Y") >> myfile.log
0
JAaron AndersonProgramming Architect @ Widener UniversityAuthor Commented:
freakin awesome you guys rock... I aspire to be a affluent in bash as you both ... thx again woolmilkporc & HeiniHog !



done
## lol
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.