LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-08-2014, 08:09 AM   #1
keif
Member
 
Registered: Apr 2013
Posts: 107

Rep: Reputation: Disabled
Converting date feed into different date format


Hello all,

I'm grabbing information from the expiration date of java certificates from a Linux box, and I set the columns to come back as follows:

Code:
Apr 09 2014
Mar 07 2014
Mar 06 2017
Apr 10 2015
Apr 07 2014
I have these in five different variables. I would like to feed each of them into a command that converts it into a different date format, if possible.

Here is the format I have in mind:

Code:
4-9-2014
3-7-2014
3-6-2017
4-10-2015
4-7-2014
The only real difference besides the alphabetic change is the elimination of the '0s' in the day column.

If anyone knows a way to do this it would be greatly appreciated.

Thanks!
 
Old 07-08-2014, 08:19 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,475

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
What have you tried so far?
 
1 members found this post helpful.
Old 07-08-2014, 08:20 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
"man date" - will do all the formatting you require, including eliminating the zero padding.
 
1 members found this post helpful.
Old 07-08-2014, 08:26 AM   #4
keif
Member
 
Registered: Apr 2013
Posts: 107

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TenTenths View Post
What have you tried so far?
I found a way to do this:

Code:
echo "$variable" | awk '{print "date -d\""$1FS$2FS$3"\" +%m-%d-%Y"}' | bash
Thanks for the push!
 
Old 07-08-2014, 08:33 AM   #5
keif
Member
 
Registered: Apr 2013
Posts: 107

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by syg00 View Post
"man date" - will do all the formatting you require, including eliminating the zero padding.
Actually, that would be the following to eliminate the padding for the day:

Code:
echo "$variable" | awk '{print "date -d\""$1FS$2FS$3"\" +%m-%-d-%Y"}' | bash
Thanks for using the word "padding". That sent me right where I need to go :-)

Last edited by keif; 07-08-2014 at 08:34 AM. Reason: - for day
 
Old 07-08-2014, 08:39 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,838

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
that will not remove 0s from the day coloumn.
also
date -d "$variable" '+%m-%-d-%Y'
will make the same thing.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
python script converting date to iso format vikatakavi Programming 3 10-16-2013 04:01 PM
Need help on converting date time format in text file and triggering action depam Linux - General 3 11-28-2012 09:46 AM
LXer: How to change Thunderbird's date format in Date column LXer Syndicated Linux News 0 07-18-2012 02:11 AM
Help, converting date format in a comma separated field! mgsmith7475 Programming 2 04-09-2010 11:34 AM
Converting a date in MySQL format to human readable in Perl resetreset Programming 7 02-11-2009 07:14 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration