Korn Shell Date Formatting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Korn Shell Date Formatting
# 1  
Old 07-01-2011
Korn Shell Date Formatting

I am serching for a file created today like so:

Code:
 
 
TODAY=$(date +"%b-%d")
 
T_FILE=$(find /export/home/dan/ck/reports/t-status-t.txt-$TODAY-05-00-0?.csv)

The file it is searching for is titled:

Code:
 
/export/home/dan/ck/reports/t-status-t.txt-Jun-29-05-00-01

however, I when the day of the month is between 1 and 9, the file generated is in the following format:

Code:
 
 
/export/home/dan/ck/reports/t-status-t.txt-Jul--1-05-00-01.

So I would like a way for the date format to be able to look for both Jul--1, Jul--2, Jul--3.....Jul--9, Jul-10, Jul-11 and so on. This should be applicable for every month of the year...
any suggestions? The only thing that comes to mind is an if statement but I was wondering if there was an easier way....Thanks.
# 2  
Old 07-01-2011
This will do it:
Code:
date +"%b-%d" | sed 's/-0/--/'

This User Gave Thanks to Shell_Life For This Post:
# 3  
Old 07-01-2011
Code:
TODAY=$(date +"%b-%d" | sed 's/-0/--/')

This User Gave Thanks to ctsgnb For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Need Date Formatting help

Hi, How can i store the date + time from the output of the ls command in loop in a variable date1? -rw-rw---- 1 user1 admin 500002 Jan 2 21:24 P002607.cssI then want to convert Jan 2 21:24 to this date format 2014-01-02 21:24:00 and save it in date2 variable. Then i would like to add... (1 Reply)
Discussion started by: mohtashims
1 Replies

2. Shell Programming and Scripting

How to do Date Manupulation in Korn Shell?

Hi All, I need to find the date 19days back from the current date: eg: if today is 17 March 2013 then the output should be : 26 Feb 2013 Can i do this using date command in Korn Shell? And also if i need future 15 days date from current date, how to that? Any help appreciated :) ... (3 Replies)
Discussion started by: Arun Mishra
3 Replies

3. Shell Programming and Scripting

Date formatting in shell script

Hi, I am writing a script and I need to calculate last weeks date. I get the current date as; today=`date '+%Y%m%d'` and I need last week inthe same format. Thanks, (2 Replies)
Discussion started by: ozum
2 Replies

4. OS X (Apple)

Date Formatting, etc.

Hi - I'm using GeekTool to customize my desktop in OS X 10.5.8 I'm a complete novice as far as UNIX commands, just know enough to be dangerous. I have a command entered as a Shell to display my events from iCal: This makes my events show something like this: While this is... (1 Reply)
Discussion started by: patricksprague
1 Replies

5. Shell Programming and Scripting

date formatting

Hi i need to have the date in the format like dd-mon-yyyy my script goes like this #!/usr/bin/bash for f in /space/can /home/lbs/current/externalcdrbackup/L_CDR_Configuration/1/200903122* ; do awk '{sum++;}END{for(i in sum) {print d,h,m,i, sum}}' "d=$(date +'%m-%d-%Y')" "h=$(date +'%H')"... (8 Replies)
Discussion started by: aemunathan
8 Replies

6. Shell Programming and Scripting

Korn Shell Script - Getting yesterdays date

I need to get yesterdays date in the format yyyymmdd I can get today's date simply enough - 20031112 Is there any way to substract 1 from this easily enough in korn shell script? It has to be korn shell and not perl (20 Replies)
Discussion started by: frustrated1
20 Replies

7. UNIX for Advanced & Expert Users

Date Formatting in Shell Script

Hi, Can anybody throw somelight on how to handle date in a shell script? I need to pass the date in this format 'yymmdd' and then pad it to a file. The way in which i've handled is given below, but the date is not getting passed rather the file is getting created with a null date. Any... (2 Replies)
Discussion started by: Isiva
2 Replies

8. UNIX for Dummies Questions & Answers

Date formatting

Running bash how do I input the date in the command line like 3/20/90 and get an output formmated like March, 20 1990. (8 Replies)
Discussion started by: knc9233
8 Replies

9. Shell Programming and Scripting

date formatting

Date format MM/DD/YYYY required is YYYYMMDD, I tried using sed but could not get it any help please. (4 Replies)
Discussion started by: mgirinath
4 Replies

10. Shell Programming and Scripting

Formatting date

i need date in the following format December 14, 2005. With date +"%b %d, %Y" command i am getting the following output :- Dec 14, 2005. can anyone pls tell me how to get the full month name (2 Replies)
Discussion started by: radhika03
2 Replies
Login or Register to Ask a Question