The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
changing the format of date in unix trichyselva UNIX for Dummies Questions & Answers 5 03-20-2008 10:07 AM
convert mmddyy date format to ccyyddd format?? Bhups Shell Programming and Scripting 2 09-27-2006 08:30 PM
changing the format of date nasirgondal Post Here to Contact Site Administrators and Moderators 1 06-07-2006 10:37 PM
Changing the format of date nhatch UNIX for Dummies Questions & Answers 4 04-11-2006 07:17 AM
Changing date format Sabari Nath S Shell Programming and Scripting 5 12-07-2005 12:38 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 06-07-2005
Registered User
 

Join Date: Jun 2005
Posts: 5
Changing the date format

Hi,

I know there is a Q/A section and lots of posts regarding date command here. I am sorry to start a new thread. I am very new to shell scripting (actually i am working on my first program), so please forgive my ignorance. I could not find an answer to my problem else where so i posted it here.
I appreciated if anyone would refer me to a source where i can get my answer or give me some suggestions on how to resolve the matter.

This is what i need to do:

I am trying to use a shell script in Linux to read the current time and change the format to M_D_YYYY.
then the program needs to search the current directory for a file named "InfoM_D_YYY" (for example 'Info6_7_2005' ), read the file and write the data in separate variables.
When i use the date command, the out put is formated as follows:

Tue Jun 7 12:55:12 UTC 2005

I do nto know how i can change this format to M_D_YYYY and save in a variable which i can later ue to search for a file named InfoM_D_YYYY.

Again, I am sorry if this question is repetitive.

Thank you,

Nina
Reply With Quote
Forum Sponsor
  #2  
Old 06-07-2005
Registered User
 

Join Date: May 2005
Posts: 80
am not sure if this will work in Linux, but in AIX its as follows :-
DT=`date +"%m_%d_%Y`

Cheers

J
Reply With Quote
  #3  
Old 06-07-2005
Registered User
 

Join Date: Jun 2005
Posts: 5
Quote:
Originally Posted by jhansrod
am not sure if this will work in Linux, but in AIX its as follows :-
DT=`date +"%m_%d_%Y`

Cheers

J
Thank you for your response.

It did not work though. I got the following error:

date: illegal time format
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
[-f fmt date | [[[[[cc]yy]mm]dd]HH]MM[.ss]] [+format]
DT=: Command not found.


Nina
Reply With Quote
  #4  
Old 06-07-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,003
DT=`date +%m_%d_%Y`
echo "${DT}"
Reply With Quote
  #5  
Old 06-07-2005
Registered User
 

Join Date: Mar 2005
Posts: 64
The error message itself gave you the answer to your question, in full detail
Reply With Quote
  #6  
Old 06-07-2005
Registered User
 

Join Date: May 2005
Posts: 80
Typo error. I forgot the second quote.

DT=`date +"%m_%d_%Y"`
Reply With Quote
  #7  
Old 06-08-2005
Registered User
 

Join Date: Jun 2005
Posts: 5
Hi,

when i use DT=`date +"%m_%d_%Y"` in a tcsh shell, i get the message that
DT=06_08_2005: Command not found.
Actually for any variable assignment (even the very basic ones like
var=10 i get the error message that var=10: Command not found.
But in kshell it works fine. But it has the format of say 06_07_2005. Do you know how i can get rid of the 0's in month and day and get something like 6_7_2005.

One more question, i do not understand why the same command works in kshell but not tcsh. can anyone explain please.

Thank you

Nina
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
linux

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:34 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0