![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| convert date format YYYYMMDD to MM/DD/YYYY | nasirgondal | Shell Programming and Scripting | 8 | 04-08-2009 10:56 AM |
| create filename with 'DD/MM/YYYY' date format | royalibrahim | Shell Programming and Scripting | 4 | 04-12-2008 08:24 AM |
| Date Vadidation in YYYY-MM-DD | itsmehihihi | Shell Programming and Scripting | 1 | 07-22-2007 09:22 PM |
| sed to display date in dd/mm/yyyy format | sars | Shell Programming and Scripting | 2 | 02-15-2007 03:32 AM |
| changing YYYY-MM-DD to DDMMYY | hcclnoodles | Shell Programming and Scripting | 3 | 07-29-2004 07:48 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Next time you should mention your shell and your OS from the beginning
Code:
echo "28-Mar-2008" | date -d - "+%m/%d/%Y" Code:
#!/bin/ksh d="28-Mar-2008" date -d $d "+%m/%d/%Y" |
|
||||
|
Not all date implementations have all this fancy shmancy stuff. As a matter of fact, on HP-UX or Sun, you should be thankful that it even displays today's date.
If you can't get a good date (sorry, couldn't resist), then yes, sed (or cut, or awk, or perl, or nearly any programming language you happen to know the basics of) can be used to move around parts within the string. (True story from real life: I had a colleague who needed to remove duplicate lines from a file. I intercepted him when he had exported the file to his University account and loaded it into SPSS which he was more familiar with, but couldn't quite get to do this precise task.) But yes, you need the month name to number mapping somehow. somebody posted one awk solution the other day, but I can't seem to find it now. If the input is just the date then twelve lines of sed will do it. |
|
||||
|
Quote:
Code:
# echo "dd-mmm-yyyy" | awk 'BEGIN{FS="-";OFS="/"}{print $2,$1,$3}'
mmm/dd/yyyy
|
|
||||
|
Add to the BEGIN { m[jan] = 1; m[feb] = 2; ... etc } and there you have it. Like I said, somebody posted code like this I think only yesterday, but I wasn't able to bring it up with a search.
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|