How to format string/date in bash?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to format string/date in bash?
# 1  
Old 07-26-2011
How to format string/date in bash?

I have string like "1-JUN-11"
and it needs to be converted to "01JUN11" and "1/6/2011"SmilieSmilieSmilie

Thanks
# 2  
Old 07-26-2011
Hi,

Test next commands:
Code:
$ date --date=1-jun-11 +%d%b%y
01jun11
$ date --date=1-jun-11 +%e/%m/%Y | sed -e 's/^ //' -e 's/\/0\([1-9]\)\//\/\1\//'
1/6/2011

Regards,
Birei
This User Gave Thanks to birei For This Post:
# 3  
Old 07-26-2011
Awesome!!!!SmilieSmilieSmilieSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash Scripting with date format conversion

I have a script below and wanted to change the output into three different file format (3 separate script) #!bin/bash #input file format postwrf_d01_20131206_0600_f08400.grb2 #postwrf_d01_YYYYMMDD_ZZZZ_f0HHHH.grb2 #zzzz= 0000,0600,1200,1800 (in UTC) #HHHH=00000,00600,01200,01800 ..ect (in... (1 Reply)
Discussion started by: cumulus_255
1 Replies

2. Shell Programming and Scripting

Show the string in date format

Hello guys. how can print the: 20140206 like Fri, Feb 6, 2015 Thank you. (4 Replies)
Discussion started by: Ymir
4 Replies

3. Shell Programming and Scripting

Convert string into date format

Hi, I am getting the below string as a input for date. 12/03/2013 11:02 AM I want to change this date as 03-DEC-2013 11:02 AM. Could you please help on this. Thanks Chelladurai (4 Replies)
Discussion started by: ckchelladurai
4 Replies

4. UNIX for Dummies Questions & Answers

Date format in Bash Script

Hi Experts I'm struggling with the dates in bash scripting. here is my code due1=`grep "$member" Due.txt | tail -n 1 | cut -d "," -f2 | tr -d "\15"` duedate1=`date +%Y-%m-%$due1` echo $due1 echo $duedate1 if I execute the above code I get output as 10 2013-09 %10 ... (2 Replies)
Discussion started by: parpaa
2 Replies

5. UNIX for Dummies Questions & Answers

Date format in Bash Script

Hi Experts, We get "Day" of a month in a variable, so how to make date of out it? To make more sense if my variable $DAY contains "12" and month and year will be current date (as of today) so I want to see as output as 2013-09-12. How can I achive this bash script?? Any help is... (4 Replies)
Discussion started by: parpaa
4 Replies

6. Shell Programming and Scripting

Compare Date with String in date format

Hi, I am new to this forum, searched, but for some reason did not find much help, so a new thread. I am trying to compare date with a string which is in date format , but for some reason, system does not give me the right result. Date is coming in a file and i am comparing the same with... (2 Replies)
Discussion started by: mkstool
2 Replies

7. Homework & Coursework Questions

Date comparison with 'string date having slashes and time zone' in Bash only

1. The problem statement, all variables and given/known data: I have standard web server log file. It contains different columns (like IP address, request result code, request type etc) including a date column with the format . I have developed a log analysis command line utility that displays... (1 Reply)
Discussion started by: TariqYousaf
1 Replies

8. Shell Programming and Scripting

Which is the STRING format in the date command?

Hi According with the 'date' command documentation My question is, which are the possible values for STRING? I have been looking in the man pages but I didn't find anything? After some googling I have found it can have special values as 'now', 'yesterday' or 'tomorrow'. If it represents... (1 Reply)
Discussion started by: islegmar
1 Replies

9. UNIX for Dummies Questions & Answers

How to format a date string

I have a file tmp.out with contents: 20080812 02:41:07 20080812 05:03:04 20080812 05:46:16 How do I format the contents such as: 2008-08-12 02:41:07 2008-08-12 05:03:04 2008-08-12 05:46:16 Thanks, - CB (2 Replies)
Discussion started by: ChicagoBlues
2 Replies

10. UNIX for Dummies Questions & Answers

bash date format

hi guys. in bash is there any other way of limiting the time displayed to HH:MM appart from (date +"%H:%M") and (date +"%R")? i want to input time into a database in the form HH:MM have tried NOW() but this gives me HH:MM:SS thanks in advance (1 Reply)
Discussion started by: vadharah
1 Replies
Login or Register to Ask a Question